View Single Post
Super Moderator
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 03-13-2014, 09:04 AM

Originally Posted by Sharris View Post
So far I have him saying the 99 bottles of pop and the loop to set at repeat 96 times like the instructions say, but I'm stuck from there.
I do not know what your actual assignment is but I think there are two things you need to do:
1. Keep track of the number of bottles left.
2. Get that number into a "Say" statement along with " bottles of pop on the wall.
The first one is relatively easy as you are using a loop. On the loop click "Show complicated version" you will see something like this:
Loop index from 0 up to (but not including ) 96 times incrementing by 1
This is telling you that there is a numeric variable called index that will start at 0 and add 1 each time the loop is completed (the increment by 1 part) stopping when the index reaches 96. Note: loop 96 is skipped but the loop has been done 96 times since it started at 0.
So you have "index" that goes from 0 up to 95 but need a value that goes from 99 down to 5. To do this create a number variable, either a global (world) variable or one local to your method, and name it bottles. Within the loop set bottles to 99 - index. You will find index listed under expressions when you are completing the - part of the expression.

Now you have a variable called bottles that goes from 99 to 5, but how do you put that into a Say statement?
The short answer is that you create the string you need. There are a couple of parts to this but it is not really hard.
First create string variable called "lyric" and drag into the Loop just after the
bottles set value to (99-index)
Set the value to anything because you are going to change it anyway. So initially you might have:
bottles set value to (99-index)
lyric set value to default string
Now make sure the world is selected in the object tree and pick the function tab in the world's details. Scroll down to the "string" section, grab "what as a string" and drag it to "default string" so it will replace it. Go to expressions and select "bottles" and now you have:
bottles set value to (99-index)
lyric set value to bottles as a string
Now under the string section of functions, grab "a joined with b" and drag it over to replace "bottles as a string" this will put the "bottles as a string" into the "a" part; for the "b" part pick other and type " bottles of pop on the wall." The code should now look something like:
bottles set value to (99-index)
lyric set value to bottles as a string joined with bottles of pop on the wall.
And finally, pick your character drag the say instruction into your method and pick expressions lyric.

That should do it

Mark Henwood
Reply With Quote