GameMaker How Do Seeds Work?

NotTayyy

Member
Hi I Had an Idea to Have a Random number that is Set at the beginning of thegame and depending on what number was rolled you would get slight variations to the main game.

But I Was wondering, How does Seeds work, Is the seed That I Export the Game With The Seed everyone Gets? Or is the Seed random for Everyone?

I Know Randomize(); randomizes the seed with every restart, But I Just want Every Person To get an Initial random number Then It Stays The Same For That Save File I Guess.
 

CloseRange

Member
Little confused by what exactly you're asking.
a seed will determine what functions like random and random_range will produce.
If you never call randomize then the seed is always the same no matter how many times you run the game or who gets the game.

If you wish to set your own seed instead of getting a random one you can use random_set_seed()
If you wish to save the seed for further use then use the function random_get_seed() and save that into a file
then when you go to reload the file use random_set_seed()
 
C

Catastrophe

Guest
So, the way you use seeds is

1) When starting your game, you do
randomize()
seed = random_get_seed();
(do your world building)

2) when saving, save this seed

3) when loading
seed = (load the saved seed)
random_set_seed(seed)
rebuild your world


Keep in mind, if you're using seeds this way, you cannot have your randomized world be determined by other variables like maincharacter.level or something, and it all has to be done at once at start. If you want to do procedural generation of dungeon levels or things like that, you need to make seeds for each level, or generate them at game start as well.

Edit: Acually, you said "small variations" It sounds like you don't want seeding at all. Just call randomize() at start of game and use the random functions. You should elaborate on exactly what you want.

Edit: missed the random_set_seed()
 
Last edited by a moderator:

TheouAegis

Member
After you set the seed once, every time you call a random or irandom function, the seed will be incremented a specific amount. This should be the sameacross all iterations, so if you set a seed to n, run 20 random calls, set the seed to n again and run 20 more randoms, the sequence should be the same.
 
Top