PDA

View Full Version : Assignment 6 99 bottles


Sharris
03-12-2014, 01:49 PM
I am having trouble getting the numbers to decrease automatically as my character sings the song. Can anyone help me with this assignment?

chickentree
03-12-2014, 01:57 PM
I am having trouble getting the numbers to decrease automatically as my character sings the song. Can anyone help me with this assignment?

What have you got so far?

Sharris
03-12-2014, 02:28 PM
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.

chickentree
03-13-2014, 09:04 AM
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) statement.
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

MrMoke
03-13-2014, 03:03 PM
Another option might be to use a "While Loop".

Create a numeric variable called something like"bottles" and set to 99.
Start a "While" that loops as long as "bottles" is greater than zero.
Add your code to the While Loop.
The last two lines are "Take one down, pass it around.", and "(bottles-1) bottles etc...", so you decrement "bottles" variable between the two lines and avoid All the inline subtractions.

Other things you might want to consider:
1) Using int(bottles) to get rid of decimal positions in say commands.
2) Make the last statement in the Loop an If/Else statement that changes the last "say" line to "no Bottles left on the wall" when "bottles" eventually gets to zero.