Alice Community Lab 2 spinning loops

 Lab 2 spinning loops
 BadWolfGeronimo Junior Member   Status: Offline Posts: 14 Join Date: Dec 2016 Lab 2 spinning loops - 12-31-2016, 04:59 PM This assignment is making me crazy. I feel pretty confident with loops but having the "Should I spin again?" question accept yes, Yes, and YES is something I cannot understand. My thought process is to use a variable with no as the value and set the boolean equation so that if the answer is not No, then it accepts it and spins again. But apparently booleans and myself do not get along. I have been working on this for days now. I've read all the other posts about lab 2 and I see someone made their own function to accept a b and c. How do I do that?
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
01-01-2017, 06:17 PM

Quote:
 Originally Posted by BadWolfGeronimo This assignment is making me crazy. I feel pretty confident with loops but having the "Should I spin again?" question accept yes, Yes, and YES is something I cannot understand. My thought process is to use a variable with no as the value and set the boolean equation so that if the answer is not No, then it accepts it and spins again. But apparently booleans and myself do not get along. I have been working on this for days now. I've read all the other posts about lab 2 and I see someone made their own function to accept a b and c. How do I do that?
The way you have been trying would sort of work.
The problem is that, if done correctly, the program would accept anything except "No" as being yes. This would include "yes", "Yes", "YES", "no", "nO", and "Reading law in 2017 is boring." which is not what you want.
A couple of things before looking at a possible answer. Alice allows you to "play around" so in working out a problem you can (should, must!!) use this to understand how the program works. One of the most useful, and unmentioned, tools in this respect is the print instruction which you can access at the bottom of the developer window. Before using this make sure the movie is not running in full screen or you will not see the console window when the movie runs.
Also it is important that you know when a variable changes and when it resets. A variable that is created in the world get assigned a value when the world starts and remains the same unless something in the program changes it. When a variable is defined in a method or function it resets itself each time the method or function is called and will only change if something in the method or function changes it.
It is also crucial to understand the "flow" of the program. As an example of this, lets look at a common error made by beginning students.
Code:
```world.my first method
print "Starting Movie"
While true
print "doing while loop"
Wait 2 seconds

print "While loop done, moving on"```
In this example, the last print statement will never be called and the movie will loop forever in the while statements. I included the Wait just so that the messages don't get generated faster than you can read them.

Side Comment:
The reason this runs at the start of the movie is because of the default When the world starts, do world.my first method event in the upper left portion of the development screen. If you created a new method, lets call it world.test, and replace world.my first method with world.test in the When the world starts event, world.my first method will never be executed UNLESS something in world.test or in a method called by world.test calls it.
This means you can create a test method like world.test and swap it in and out of the When the world starts event to switch between your testing/experimental/trial code and the movie you are actually creating.
Experiment with the information above, it will pay off.

Now that I have bestowed a headache on you, lets see if we can make it start throbbing.

Since this is your second lab, I am assuming you have not been introduced to creating method or functions so lets start by just using world.my first method.

First of all start small and get the basics working. To that end lets assume that the user will only type in "yes" if they want to continue. Lets further assume that most of the time you want to continue, mostly because it makes the program easier.

In the properties tab of the world (meaning the world object is selected and you select properties in the tab on the right.), click on create new variable
1. Give the variable a descriptive name, I would use something like fContinue.
2. Select the Boolean type.
3. Make sure the default is set to true.
4. Click the "OK" button.
The f in fContinue reminds me that it is a Boolean (flag) variable and Continue reminds me exactly what it does.
In the world.my first method section add a variable, call it something like sAnswer. It can be set to the default string as its going to get changed before we use it.

The basic outline of your world.my first method will look like this:
Code:
```world.my first method

// Do the beginning stuff

print "Startup stuff done"

While world.fContinue
// Do the repeating stuff once each time we go through the loop

// Check if we are done

sAnswer set value to ask for user string question = Do you want to continue? (yes or no)

// We want to keep going so leave world.fContinue unchanged.
else
print "Exiting while loop..."
world.fContinue set value to false

// Do the shutdown stuff
print "Shutting down"
// Pause long enough to see the shutdown message.
Wait 2 seconds```
This should get you started, if you work though how the code works, the part you need to modify to look for other answers should become obvious.
If you find you are still having trouble, please respond to this this thread and include your Alice movie.

Mark

Mark Henwood
mhenwood@ieee.org

Last edited by chickentree; 01-01-2017 at 06:33 PM.

 BadWolfGeronimo Junior Member   Status: Offline Posts: 14 Join Date: Dec 2016 01-01-2017, 06:51 PM I've submitted the project with the simple yes/no answer but I will definitely come back to this thread and use the information you've provided to try to run it with the three yes's. Thank you for taking the time to help me!
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
01-02-2017, 12:24 AM

Quote:
 Originally Posted by BadWolfGeronimo I've submitted the project with the simple yes/no answer but I will definitely come back to this thread and use the information you've provided to try to run it with the three yes's. Thank you for taking the time to help me!
Ahhhh! No, please don't just take my starting point as the answer. It's purpose and the reason I responded is to help you and others to make progress and understand how to think through a problem.

Mark

Mark Henwood
mhenwood@ieee.org

 BadWolfGeronimo Junior Member   Status: Offline Posts: 14 Join Date: Dec 2016 01-03-2017, 12:42 PM I didn't copy anything. I already had the simple yes/no version worked out and saved. The three yes version got us bonus points so I was attempting to write that one as well. Unfortunately I ran out of time.
chickentree
Super Moderator

Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
01-03-2017, 06:38 PM

Quote:
 Originally Posted by BadWolfGeronimo I didn't copy anything. I already had the simple yes/no version worked out and saved. The three yes version got us bonus points so I was attempting to write that one as well. Unfortunately I ran out of time.
Ah, thank you for the response.

Mark Henwood
mhenwood@ieee.org

 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