Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Lab 2 spinning loops (http://www.alice.org/community/showthread.php?t=11650)

Lab 2 spinning loops

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 01-01-2017 05:17 PM

[QUOTE=BadWolfGeronimo;57447]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?[/QUOTE]

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 [B]in the method or function[/B] 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"
[/CODE]

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:[INDENT]The reason this runs at the start of the movie is because of the default [U]When the world starts, do [I]world.my first method[/I][/U] event in the upper left portion of the development screen. If you created a new method, lets call it [I]world.test[/I], and replace [I]world.my first method[/I] with [I]world.test[/I] in the [U]When the world starts[/U] event, [I]world.my first method[/I] will never be executed UNLESS something in [I]world.test[/I] or in a method called by [I]world.test[/I] calls it.
This means you can create a test method like [I]world.test[/I] and swap it in and out of the [U]When the world starts[/U] event to switch between your testing/experimental/trial code and the movie you are actually creating.[/INDENT]
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.:D

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 [I]world.my first method[/I].

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[U] properties tab[/U] of the [I]world[/I] (meaning the world object is selected and you select properties in the tab on the right.), click on[U] create new variable[/U] [LIST=1][*]Give the variable a descriptive name, I would use something like fContinue. [*]Select the Boolean type.[*]Make sure the default is set to true.[*]Click the "OK" button.[/LIST]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
[/CODE]

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

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 01-01-2017 11:24 PM

[QUOTE=BadWolfGeronimo;57450]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![/QUOTE]

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

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 01-03-2017 05:38 PM

[QUOTE=BadWolfGeronimo;57452]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.[/QUOTE]

Ah, thank you for the response.