I was wondering if there is any way to Randomize() the Random() function. because I have something like this:
int a;
function game_start() {
a = Random(100);
}
It works fine, but I want it so that when I restart the game, it randomizes those variables again. I tried SetRestartPoint(); before that but nothing happened. it seems that my randomized variables remained the same.
The problem is that, using RestartGame() merely just does a RestoreGame() action, loading the game saved (I think it's #999) when SetRestartGame() was invoked, so it's after all the initialization stuff were done (so all the variables were set and saved as game_start() won't be executed again).
This is an idea to do the job.
First, if there're multiple random variables set, you may better move them to a function first, just for convenience's sake (as you need to call this again when a game is restarted) , like:
function InitRandomThingie() {
haha = Random(100);
blah = Random(1000);
...
}
and call it once in game_start().
Then in the on_event() function add:
if (event == eEventRestoreGame&&data==999) InitRandomThingie();
That's all!
You can also do this:
Quote from: SteveMcCrea on Fri 26/05/2006 01:03:09It's probably because the random number generator is reset when the game is restarted, so it produces the same values again.
Try using the current time to randomise the sequence.
DateTime *dt = DateTime.Now;
int i = 0;
while (i < dt.Second)
{
int dummy = Random(1);
i++;
}
// your code here
Noted that Edmundo's variables were set in game_start(), so unless he moved that part to somewhere else, the random number weren't re-generated using this method.
The easiest thing to do is invoke the system timer... the amount of milliseconds since midnight is, for all practical purposes, random.
The method I mention seems to be simplest, and it doesn't even need to use time functions, and it seemed to work when I tested it.
A: No, my method is simpler.
B: No, MY method is simpler.
A: Mine.
B: Mine!
A: MINE!
B: Slacker.
A: Loser.
B: Ruffian.
A: Fop.
(insert rest of Fettucini quote here :) )
*Use boiling pot with fetuccini brothers.*
Guys, Gilbert's solution worked just fine. I really didn't know that AGS quirk about restarting the game. I guess you learn something new every day.