Thread: Space Jump
View Single Post
cedricdosss Space Jump
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default cedricdosss Space Jump - 11-15-2012, 10:11 AM

Quote:
Originally Posted by cedricdosss View Post
Hello, I'm working on this project can someone help me?
Create a world with an astronaut, moon surface, and Lunar Lander (LL). (Web Gallery). Using the “ask the user for a number” function, have the astronaut jump a specific height (but must be visible at all times). The value must be greater than zero, and if not, give and error message and repeat the question until a valid answer is given.

I have the most part, but can't get it to ask again until the valid answer is given.
Can anyone help?
Thanks
Hey cedricdosss, I looked at your Space Jump program and it looks like you put all of your code into one if/else statement. If you want your code to re-ask the user for a number when they enter anything 0 or less, then you'll have to use a loop. There are two kinds of loops you can use for this. The easiest is a recursive loop which basically just calls the method that you made to run it again. To do this just drag "my first method" to the place right after you have your astronaut say "Error". This should fix your problem.
Recursive loops are not a good habit to get into, though. They give you problems with lag when you recursively loop the same method a few thousand times.

A while loop is much better to use. I made the program for you with a while loop in case you want to see how it will work. I also made your animation MUCH smoother and better looking (I even finished your jump for you, you just had him suspended in mid air). You can download my version and see what I fixed. I made a world number variable called "input" and had it set to 0, and then put a while statement saying that while "input" is less than 0, it keeps asking you for a new number, and then when "input" is over 0, it preforms the animation, and when that is done the program ends.

Download from the link below and tell me what you think of the improvement I made on the animations.
Attached Files
File Type: a2w Space Jump (1).a2w (2.23 MB, 20 views)


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
   
Reply With Quote