• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Synchronizing random Numbers between two versions of the same game for Multiplayer Purposes - Need Help!

I am working on a multiplayer RTS game, and I have a little problem. I managed to set the same type of seed between two copies of the game, yet every time I generate a unit, it has a different random number between the other copy of the game, compared to the first copy, when the same unit is supposed to have the same random number between the two copies. Is there some way of allowing the same number be shared between the master and slave unit objects? Is there some sort of code to help me with this problem? If anyone can help me, I would greatly appreciate it.
 

FrostyCat

Member
You bought into a myth. Having a fixed seed is not enough to guarantee deterministic outcomes from a random number generator, the other requirement is calling random-dependent functions the exact same number of times in the exact same order. With input and network delays in the mix, this almost NEVER pans out.

This is why the standard practice is to have a central server or one of the peers hold the authoritative game state, and synchronizing other peers with that. Seeds are only ever used to generate the level or perform some other one-time setup action, they are not used to synchronize anything ongoing.
 

chamaeleon

Member
I am working on a multiplayer RTS game, and I have a little problem. I managed to set the same type of seed between two copies of the game, yet every time I generate a unit, it has a different random number between the other copy of the game, compared to the first copy, when the same unit is supposed to have the same random number between the two copies. Is there some way of allowing the same number be shared between the master and slave unit objects? Is there some sort of code to help me with this problem? If anyone can help me, I would greatly appreciate it.
Sounds terribly fragile, especially if you use the built-in random number generator. Even if you managed to start off synchronized, a single use of a random function at any point by one of the clients and not the other would throw it all off. My suggestion is to make one of the instances (or a server middle-man) the generator of random numbers that should be synchronized across clients.

And, what's this "shared between master and slave unit objects" anyway? If you haven't implemented sending of information between something, GMS will not do anything to help you at all. It is 100% up to you to ensure every bit of needed information is sent appropriately.
 
Top