Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   random objects in an if/else (http://www.alice.org/community/showthread.php?t=4214)

Porpoise 04-09-2010 04:34 AM

random objects in an if/else
 
1 Attachment(s)
I have a question about selecting a random object from a list and using the object selected in an if/else.

More specifically, I am working on a game of wack-a-mole (with hares instead of moles) and I want to make an if/else statement that asks "if the random hare selected is below ground, move the same random object selected up .5 meters. Else, do nothing.

Hopefully the end result will be Alice selecting a hare at random and moving its head above the ground if it it currently below it, and then go back down when you click on it.

Currently, i have it set up so that a specific object chosen by me (hare1, hare2, ect.) goes up the height of its head and gives the player 3 seconds to click it. after the 3 seconds are up, it checks whether it is above or below ground (If the player clicked it, it should be below ground). If it is below ground, it makes the next one go up. If it is above ground (meaning the player hasn't clicked it), it goes down on its own and the next one goes up.

thanks in advance.

bjia56 04-09-2010 07:51 AM

You could try having a random number command right before your if/else, then use that random number to choose an element from the list.

If this isn't for a school assignment I could possibly make an example for you.

EDIT: Your current world is looking pretty good. As a friendly suggestion, try to have it so that the player cannot click on the hares during the intro.

Porpoise 04-09-2010 04:14 PM

1 Attachment(s)
Thanks so much, after reading your post i thought about it and set variables to random numbers and put all the hares into a list. So when the "hareup" method is called, it calls a random hare from the list.

I also took your advice and made the hares unclickable during the intro.

Again thank you for your help.

Re-uploading in case anyone stumbles on this thread and wants to see my code so they can be inspired on their own projects.

bjia56 04-09-2010 05:13 PM

No problem, glad to help!


All times are GMT -5. The time now is 05:54 AM.

Copyright ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.