Alice Community

Alice Community (
-   How do I...? (
-   -   Random movement of objects in an array/index? (

GameBredDJ 05-24-2012 11:09 PM

Random movement of objects in an array/index?
I have a project due pretty soon and needed a bit of advice. I have to make (let's say) 5 object in an array move randomly in different directions on screen. Let's say you have 5 roaches on a page and you want all of them to move in different directions randomly, how would I go about the? I have no problem creating and adding object to an array. My problem is the random movement of each individual objects. Any help or advice would be very appreciated.

x2495iiii 05-25-2012 01:37 AM

Does the movement need to be simultaneous?

Mr Kidnapper 05-25-2012 02:41 AM

Well if you searched the forum and my posts I had actually answered in detail how to do this assignment.

But I'm too lazy to do that myself so I'll keep it simple.
You know how to make a random number right?
All of Alice's units are in percent-decimal so remember to convert it if you use radians or degrees.
For All Together is what you're looking for. It's a loop function for arrays that does it for all items at the same time.
Create random number. It's somewhere in the World's functions. You'll probably be able to figure out what the maximum and minimum number you have to generate is. Keep in mind that if you create this random number in the For All Together, it will be different for each element in the array. If you want it to be the same, then you need to create it outside of the For All Together as a variable.
You can use this same method for turning as well as distance moved.

All times are GMT -5. The time now is 03:02 PM.

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