ok, so here is how to create a random number generator:
Define G_CURRFRAME in def.gs
then put the following code in the HandlerGameUpdate() function in handlers.gs:
GameSet(G_CURRFRAME,GameGet(G_CURRFRAME)+1);
if (GameGet(G_CURRFRAME)==60) { GameSet(G_CURRFRAME,0); }
the number 60 is an arbitrary number, you cannot call a random number higher than this. if you need to call a higher number, change 60 to a higher number
and put the following code in utils.gs:
/////////////////////////////////////////////////////////
//randomiser based on a game frame counter
/////////////////////////////////////////////////////////
func time_rand(num)
{
sec = GameGet(G_CURRFRAME);
// if number range required is lower than the 'frame' number,
// reduce that number in increments until it is lower
if (num-1< sec) { for(i=sec;i>num-1;i-=num)
rand = i-num;
}
else // else set the random number as whatever the 'frame' number is
{
rand=sec;
}
GameSet(G_CURRFRAME,60-sec);
return rand;
}
when called, this basically finds the current game 'frame' number. if it is lower than the random number range, it sets the random number as that, otherwise it reduces it in increments until it is lower, then sets the random number as the resulting number.
the beauty of this is that is really is truly random, as the frame counter changes so quickly that it's impossible to 'fix' it to the same number again and again. it depends on when various things in the game happen, rather than an in-game number generator. {yolkfolk}:delight:
unfortunately if you request another random number straight after, the frame count will not have moved on, so if the start number is the same, the resulting number will be the same too. Still working on how i can fix that...
EDIT:: thought of a way to do it. i added GameSet(G_CURRFRAME,60-sec); near the end, which has the effect of 'reversing' the number, ready for if there is a command calling it straight after. again, if you change the number '60' in the handler code, you will need to change it here too. :smile: