• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML How to save random variables?

D

dovenfrosken

Guest
Hello, I have a problem- I need to save random variable, but functions like choose(); update variable every half of second, but I want the randomization of the randomwalk to stop when the character is walking.

//step event
if (patrol){
randomwalk = choose(-1, 1); //random variable
if (walking > 0){ //if walk
walking -= 1; //timer expires
movespeed = 0.4;
dir = randomwalk; //random dir
}
else{
if (staydelay > 0){ //if stay
staydelay -= 1; //timer expires
movespeed = 0; //stay
}
else{ //refill cooldowns
staydelay = staydelaymax;
walking = walkingmax;
}
}
}
 

Roderick

Member
Please use [code ] blocks to make your code more readable.

You just need make sure it only checks when you want it to. Depending on the rest of your code, you may have to do something different than what I did, but something similar to this should work.

Code:
//step event
if (patrol){
    if (walking > 0){ //if walk
        walking -= 1; //timer expires
        movespeed = 0.4;
        dir = randomwalk; //random dir
    else {
        randomwalk = choose(-1, 1); //random variable}
    }
else{
if (staydelay > 0){ //if stay
    staydelay -= 1; //timer expires
    movespeed = 0; //stay
        }
        else{ //refill cooldowns
        staydelay = staydelaymax;
        walking = walkingmax;
        }
    }
}
 
Top