Alice Community Assignment 6 99 bottles

 Assignment 6 99 bottles
 Sharris Member   Status: Offline Posts: 15 Join Date: Jan 2014 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?
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
03-12-2014, 02:57 PM

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

 So far
 Sharris Member   Status: Offline Posts: 15 Join Date: Jan 2014 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.
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
03-13-2014, 10:04 AM

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

 Another Option
 MrMoke Senior Member     Status: Offline Posts: 501 Join Date: Sep 2007 Location: Austin, Texas 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.

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge