• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Questions About Desynchronization in games.

Status
Not open for further replies.
Level 9
Joined
Nov 4, 2007
Messages
933
Hope I spelled desyn right, but anyway my question is what causes an online battle.net game to desync, I haven't gotten any real good answers to this question, just really vague responses such as "Something in the triggers," if you have an answer please post, it'd be very helpful.
 
Level 11
Joined
Feb 22, 2006
Messages
752
A game will desync if you start creating or destroying handles for one player but not for another using GetLocalPlayer(). So for example, if you do:

JASS:
function foo takes player p returns nothing
    if (GetLocalPlayer() == p) then
        call CreateUnit(p, 'hfoo', 0, 0, 0)
    endif
endfunction

you will get a desync.

EDIT: I should probably mention desyncs also happen if you start changing handle properties, like moving a unit, or setting its life/mana.

Examples of code you CAN use GetLocalPlayer() with without desyncing the game are: changing the camera, displaying multiboards/leaderboards/fade effects, enabling/disabling cinematic mode.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
You can also create a special effect that is only visible to one player.
JASS:
function CreateEffectForPlayer takes string path, real x, real y, player p returns effect
    local string s = ""
    if GetLocalPlayer() == p then
        set s = path
    endif
    set bj_lastCreatedEffect = AddSpecialEffect(path, x, y)
    return bj_lastCreatedEffect
endfunction
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Desyncs happen when you manipulate data in multiplayer that is different for 2 different players. For example:

GetUnitLifeBJ(...) will always return the same hit points for a unit, because the unit always has the same amount of hit points for player 1 AND player 2. This data is synchronised (it is the same for both players).
GetCameraTargetX() will always return different X coordinates, because the camera position of player 1 is not the same as the camera position of player 2. This data is desynchronised.

When using desynchronised data as if it's synchronised will cause a desync disconnect of either players. For example: creating a new unit at the current camera position causes a desync because it creates "synchronised" data ( a unit ) at a desynchronised position, causing the new unit to be created at different positions for both players, which obviously should not be allowed, because it essentially breaks the game.

Changing the camera position for a specific player isn't possible with natives, because camera positions are desynchronised data, i.e. you only have data on YOUR camera position, and not on player 2's camera position. Changing the position will only change *your* camera position, but because it's desynchronised data, it changes the camera positions of all players to a certain position.

GetLocalPlayer returns the local player, i.e. "you". It's desynchronised data, because for player 1 it returns a different player than for player 2. So if you need to change the camera position for only 1 player, you can use GetLocalPlayer() to be able to run a part of a trigger for only 1 specific player.

The thing is: in online gaming, every player plays his own game as if it's single player.
Net traffic will make it so each player's game will constantly be updated with the actions of the other players, so it *looks* like you're playing against other players.
If a new unit is created through triggers, every player will create the unit in his own game.
If a new unit is only created in ONE of the games, the other games will NOT have this unit. However, when updating the other player's games (so it looks like you're playing against other players), warcraft detects that your game contains a unit that all other players don't have, and you'll be disconnected because your game is not synchronised with the other games.
 
Status
Not open for further replies.
Top