Alice Community  

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

Reply
 
Thread Tools Display Modes
loop back to begining
Old
crashkarz21
Guest
 
Status:
Posts: n/a
Default loop back to begining - 05-26-2010, 09:06 AM

I have a World where I ask the user if they want to repeat the above steps with a yes or no question. If they say NO then the world ends, if they say YES I need it to loop back to the beginning to play all over again. I can not figure out the loop, can anyone help???
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 05-26-2010, 02:54 PM

Create a world boolean variable called "playAgain" and set it to true as an initial value. Then, if you have everything in "my first method", just create a while statement (it is one of the options on the bottom next to "loop") and just drag in the "playAgain" variable into it, so it says "While(playAgain)". Now drag every line of code that is in your main method into the while statement.

If you leave it the way it is now, following all my instructions up to this point, you will be able to play repeat the method over and over again forever. If you want to add the option to stop the method, add a code at the bottom of the while statement by dragging the variable "playAgain" in there, and it will say "set value". You can then set the value to true (just to get the option panel away), but then go the world functions tab and scroll down until you see "Ask yes or no", and drag that into where you are setting the value of "playAgain" at the bottom of the while statement, put it into where you set it to true.

Tell me if it does not make sense and I will provide a picture, or you can just publish your world here and I can fix it for you.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301

Last edited by Dameria; 07-26-2010 at 09:43 PM.
   
Reply With Quote
Loop
Old
DensetsuNoKaboom
Senior Member
 
DensetsuNoKaboom's Avatar
 
Status: Offline
Posts: 1,188
Join Date: May 2010
Location: e4eaf2
Default Loop - 05-26-2010, 02:57 PM

If you want it to loop back to the beginning of the method, just drag "object.method" to where the choice occurs. If you want it to loop to somewhere in the middle of the method, drag everything past the point you want it to loop back to (including that point) into a new method, then put that to where the choice occurs.


Thank you for taking the time to read this signature. This signature loves you.
   
Reply With Quote
Reply


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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.