Synchronizes the value stored in the
gamecacheunder the mission key and key. Calling this function sends a sync packet from each player in the calling context (citation needed), that is everybody sends a packet to everybody. The game then picks the first packet arrived (at the host). Often (but not always) that is the packet coming from the game host.
More interesting perhaps is the use to synchronize local data (like a player's camera position) to all other players. To do this only store and sync the value in a local context:
if GetLocalPlayer() == p then call StoreInteger(my_cache, "missionkey", "key", my_value) call SyncStoredInteger(my_cache, "missionkey", "key") endif
Now this will synchronize the local value
my_valueto each player but we don't know when each player has actually received it. You can use
TriggerSyncReadyto wait for each sync action, but it's not recommended as it is very slow and can hang for minutes (cf. sync doc) Instead it is recommended to use a rapid timer to check if the key is present in the gamecache. Note that this is still a local operation as different players can receive the sync at different times. If a player has received all the data you synchronize the fact that that player has got all the data. This is reasonably done via
TriggerRegisterPlayerUnitEvent(trig, p, EVENT_PLAYER_UNIT_SELECTED, null). Now once the last player has sent their selection event you have synchronized your data.
This is a very high-level overview and the process has many edges to look out for, so it's probably a good idea to use an already made system like this one.
SyncStoredXin a row will keep their order in the syncing process, i.e. first sync will be received first (FIFO).
You might rather use
- return type
- Source code
native SyncStoredInteger takes gamecache cache, string missionKey, string key returns nothing