Random

From Game Editor

Jump to: navigation, search

gameEditor supports several ways to create random events.

Trigger Events at Random Times

gameEditor's timers supports random length timers. When creating the timer, set the type to random, allowing you to specify a minimum length. Random timers use the time as a max length for the timer. Random timers are restricted to a single minimum time and to single trigger events, so using this method in more complex systems may result in a lot of unnecessary events.

Also, timer events cannot be manipulated after the timer has been created. You could destroy the timer, and recreate it with adjusted times. Instead you can use variables to trigger events. This method also allows for easy manipulation when dealing with clones. For a single timer per actor, you need to create an actor timer variable. The variable is just an int, named something like timerCount.

Reversing an actor's direction.

enemy -> DrawActor -> Script Editor

if(timerCount>0) // timerCount==0 means the timer is inactive
{
    timer++;
    if(timer >= minTimer + rand(timerRange))
    { // minTimer and timerRange can be variables or constants such as 60
        xvelocity*=-1;
        timer=1; // repeat
    }
}

To activate it, you have to set timer equal to 1. Keep in mind, using a variable counter means the timer will be in frames per second, rather than milliseconds like gE's timers.