• 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!

Randomized things always randomized the same way when testing?

So basically, i have codes like random() and choose() in use on many parts of my project. For example, in a room, i want the music to be random upon room start, so i use audio_play_sound(choose(music1,music2,music3),0,0) you get the idea. However, no matter how many times i test the game it always seems to start with the same music. Same goes for an object which should randomize the terrain in another room - the room layout is always the same! So, is there some real simple solution here i've just missed, or what...? It always seems to go with the one thing it randomized upon the first test, and use that always from then on.
 
M

Meowanator

Guest
Put randomize(); in the music playing code. So it would be like:
Code:
//Play random music
randomize();
audio_play_sound(choose(music1,music2,music3),0,0);
Also put randomize(); in the terrain randomizing code.
 
Put randomize(); in the music playing code. So it would be like:
Code:
//Play random music
randomize();
audio_play_sound(choose(music1,music2,music3),0,0);
Also put randomize(); in the terrain randomizing code.
You only need to do this once for each run of the program. You don't need to keep doing it for everything you want to randomize. In fact, repeatedly calling randomize can cause odd behaviour, like less random seeming results. Just a single call in a master object, or at game start is fine.
 
You need to put the command randomise() somewhere are the very start of your game.

There is information about this in the manual, as it says that to help with debugging and testing purposes if you do not use the randomise() command then all random values will be the same each time you run your game so that it can be easier to replicate issues repeatedly.

Ninja'd by Meowanator, however...

Put randomize(); in the music playing code. So it would be like:
Code:
//Play random music
randomize();
audio_play_sound(choose(music1,music2,music3),0,0);
Also put randomize(); in the terrain randomizing code.
You only need to randomise once in the project. Putting randomise in multiple places is not required at all, and ideally you should just put it at the start of your game - usually in the place where you do your initialisations.
 
thanks 4 fast replies you guys. So, basically one randomize() code at the start of the game should carry on to randomize everything the game is supposed to later on?
 
Top