Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Assignment 6 99 bottles (http://www.alice.org/community/showthread.php?t=10547)

Sharris 03-12-2014 01:49 PM

Assignment 6 99 bottles
 
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

[QUOTE=Sharris;54128]I am having trouble getting the numbers to decrease automatically as my character sings the song. Can anyone help me with this assignment?[/QUOTE]

What have you got so far?

Sharris 03-12-2014 02:28 PM

So far
 
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

[QUOTE=Sharris;54130]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.[/QUOTE]

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:
[CODE]Loop index from 0 up to (but not including ) 96 times incrementing by 1[/CODE]
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 [CODE]bottles set value to (99-index)[/CODE] statement.
Set the value to anything because you are going to change it anyway. So initially you might have:
[CODE]bottles set value to (99-index)
lyric set value to default string[/CODE]
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:
[CODE]bottles set value to (99-index)
lyric set value to bottles as a string[/CODE]
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:
[CODE]bottles set value to (99-index)
lyric set value to bottles as a string joined with bottles of pop on the wall.[/CODE]
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
 
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 [U][COLOR="Red"]between[/COLOR][/U] 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 [COLOR="Red"][U]If/Else[/U][/COLOR] statement that changes the last "say" line to "no Bottles left on the wall" when "bottles" eventually gets to zero.


All times are GMT -5. The time now is 10:49 AM.

Copyright ©2021, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.