Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Assignment 6 99 bottles
Old
Sharris
Member
 
Status: Offline
Posts: 15
Join Date: Jan 2014
Default Assignment 6 99 bottles - 03-12-2014, 02: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?
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 212
Join Date: Dec 2012
Location: Frosno, Ca
Default 03-12-2014, 02:57 PM

Quote:
Originally Posted by Sharris View Post
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?


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote
So far
Old
Sharris
Member
 
Status: Offline
Posts: 15
Join Date: Jan 2014
Default So far - 03-12-2014, 03: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.
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 212
Join Date: Dec 2012
Location: Frosno, Ca
Default 03-13-2014, 10:04 AM

Quote:
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:
Code:
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
Code:
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:
Code:
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:
Code:
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:
Code:
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


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote
Another Option
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 500
Join Date: Sep 2007
Location: Austin, Texas
Default Another Option - 03-13-2014, 04: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.

Last edited by MrMoke; 03-14-2014 at 04:15 PM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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