PDA

View Full Version : using the Math.random function



pyroki
June 28th, 2005, 12:20 PM
k my powerups are working now in my platfrorm game i just need help placing them in random places i dont really know how to use the Math.random() thing so can som1 help me?

Templarian
June 28th, 2005, 01:02 PM
trace(Math.round((Math.random ()*250)));

Where flash would trace a random number 0 to 250. You see the random() coded makes a number 0to1. This multiplied by 250 will give some really wierd number, then when its rounded it looks like just a random number which it is.

pyroki
July 4th, 2005, 01:13 PM
so how would i write that in the code under the onclipevent load or enterframe

signifer123
July 4th, 2005, 09:04 PM
if you want it ot run every time the frame refreshes then enterframe if you wantti to run only when the frame first loads then load

Seb Hughes
July 5th, 2005, 03:08 PM
Here somthing i made when i was bored, this should help you

pyroki
July 5th, 2005, 06:18 PM
thx but now how do i get it so after it randomly chooses a x point to stop and then make it drop then after a few seconds vanish then if the hero touches it to remove itself and not come back for a while

dinner dog
July 5th, 2005, 11:42 PM
This simply uses math.random() to duplicate the movie clips around the stage and the 'hero' is represented by the thing attached to the mouse. As I said in the comments in there you can duplicate the med_kits from the library and give them classes, but this way is a nice demonstration.
hope it helps.

pyroki
July 6th, 2005, 12:47 AM
thx but i need them to fall to

dinner dog
July 6th, 2005, 12:51 AM
add


if (this._y < 400){
_y += 5;
}
to the onClipEvent(enterFrame) on the med_kit. then you will need to add whatever code you use to detect platforms to make them stop when they hit one.