Random numbers are created and used in the Event editor. You should become familiar with this editor and know how to create a "Counter Object" in the level editor first.
- Create a counter object in the level editor. Name it "Random Number"
- Go to the Event editor and click on the "+" sign to add a new condition to the event
list
- Double click on the picture of the wrench and select "always", (which means that random numbers will be continually created during the game). You will notice that a condition has been added to your event list that says: "Always".
- Now follow this line out to the "cell" or "box" (in the column of the counter object named Random Number) right click on this box and select "set counter" from the menu list.
- Erase the "0" (zero) shown in the box and click on the button labeled "Edit".
- Click on the button labeled "Retrieve data from object".
- Double click on the picture of the wrench again and select "Generate a random number".
- Enter the number "11" which will create a random number in the range of "0" to "10".
 |
| Klik and play creates a random number from "0" to
one less than the number you specify ("11" – "1" = "10") |
|
- Your expression will now say "random[11]". Click on "ok" again and now you will see that the box under the counters column has a check mark in it for creating a random number between 0 and 10.
- The event list of all your conditions (including the one you just created) cycles again and again as long as your game is running, so in effect you are setting the counter to a random number all the time. You can now use this random number to do whatever it is that you created the random number for.
 |
Here are a few uses for a random number:
- As an event starter, say after the player destroys a monster you might want a random amount of time to pass before another monster appears on the screen.
- Perhaps you want to start a random number from 1 to 10 monsters per level.
- Placing monsters at random places on your playfield, (random x and y coord’s., or starting positions).
|
|