• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Desync function help!!! +REP to helper

Status
Not open for further replies.
Level 10
Joined
May 28, 2011
Messages
455
I am having painful problem with desync function. After finding solution and keep on changing the code, it still occurs. May I ask for your help to verify that each desync function is ok or not? Credit and +rep will be given to all who help me!!!

I start off with this code. Multiboard update gold amount to team only.

JASS:
        set i = 0
        loop
            exitwhen( i >= 8)

            set p = Player( i)
            
            if(IsPlayerInForce(p, Players)) then
                set playerId = GetPlayerId( p)
                set row = LoadInteger( Info_Ht, playerId, MULTIBOARD_ROW_KEY)
                set gold = MULTIBOARD_PLAYER_GOLD_COLOR_CODE + I2S(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)) + "|r"
                
                if( not IsPlayerAlly( GetLocalPlayer(), p)) then
                    set gold = ""
                endif
                
                set mbItem = MultiboardGetItem( MultiB, row, MULTIBOARD_PLAYER_GOLD)
                call MultiboardSetItemValue( mbItem, gold)
            endif
            
            set i = i + 1
        endloop
 

Deleted member 219079

D

Deleted member 219079

You can't set variables different for each player.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
how you go with things like this, like in Dota, where each team has technically different values showing for multiboard is you create 2 multiboards, and you hide one locally for one team, and another one for another team. And you update both at the same time. This way the only thing that is done locally is actually the fact that it is hidden, and since this is cosmetic only, it will not desync the game
 

Deleted member 219079

D

Deleted member 219079

More to clarify; this is the desync causer:
JASS:
if( not IsPlayerAlly( GetLocalPlayer(), p)) then
    set gold = ""
endif
You can't have different variables for each player.
 
Level 10
Joined
May 28, 2011
Messages
455
how you go with things like this, like in Dota, where each team has technically different values showing for multiboard is you create 2 multiboards, and you hide one locally for one team, and another one for another team. And you update both at the same time. This way the only thing that is done locally is actually the fact that it is hidden, and since this is cosmetic only, it will not desync the game

never tried 2 multiboards. Going to try it.

Apparently, the link i gave you apply different variable value for each player

JASS:
function Test takes nothing returns nothing
    local string s = ""
    //So the path will be nothing, so it won\'t show at all
    if GetLocalPlayer() == Player(0) then
        set s = "war3mapImported\\FX.mdl"
    //An actual path, so it <span style=\'font-style:italic;\'>will</span> have a path for that player but not for
    //the other players
    endif
    call DestroyEffect(AddSpecialEffect(s,0.,0.))
    //Don\'t use this function though, look below real quick to see the proper way to do this without disconnecting
endfunction
 

Deleted member 219079

D

Deleted member 219079

That's funny, I remember getting desync in LAN emulator from separating variables.


Guess I remembered wrong then...


Edit: @pnf imma just throw a reminder about my tutorial here...
 
Level 12
Joined
Oct 16, 2010
Messages
680
JASS:
if( not IsPlayerAlly( GetLocalPlayer(), p)) then
                    set gold = ""
                endif
                
                set mbItem = MultiboardGetItem( MultiB, row, MULTIBOARD_PLAYER_GOLD)
                call MultiboardSetItemValue( mbItem, gold)

i think the desync occures coz u set the var locally (that is ok) but u modify the board globaly

so when u set the same multiboard for all the players to a different amount to show may be the problem. unless multiboards work locally anyway
 
The problem is that you set a multiboarditem locally. While that alone theoretically shouldn't cause desyncs, it's very likely that you create a desync because of this on a different trigger referencing the item value.

When working with multiboards, I really recommend using a global array[16] of multiboards; one multiboard per player and only adjust the Show parameter locally to hide them for all players but the owner.


Also, make sure not to initialize a string locally. It causes problems with the internal string stack (that will not instantly cause desyncs, but creates a lingering possibility of doing so at a later moment as now the string tables will be async).

Move the "set gold" line out of the local block to avoid this. You use it as a temporary variable anyway, so there's no real need to have it inside the block.


Also, you should consider using a multiboard library. Approved libraries on hive have very high standards and provide a maximum of efficiency and flexibility. There is no need to do the local handling of multiboard entries on your own.
 
Level 10
Joined
May 28, 2011
Messages
455
It is fine to set a variable locally (the action itself does not desync, but desyncs could happen depending on what you do with the variable).

I don't think that code alone will desync. Is there anywhere else where you check the value of "gold"?

What players are in the force "Players"?

eh. My bad. The gold is local variable.
The force Players contain all players with playing status.

i think the desync occures coz u set the var locally (that is ok) but u modify the board globaly

so when u set the same multiboard for all the players to a different amount to show may be the problem. unless multiboards work locally anyway

I must use multiboard globally :/ Some other functions need it too...

Also, you should consider using a multiboard library. Approved libraries on hive have very high standards and provide a maximum of efficiency and flexibility. There is no need to do the local handling of multiboard entries on your own.

Multiboard library :) Thank you sir.

Apparently, after doing a lot a lot of tests, I found that this code doesnt cause desync :( Can I issue another one? When I tested it LAN, no desync happens at all. But when I test it on garena (warcraft 1.24e), desync happens to 2 players mostly with 3 v 3. But when 2 v 2, everything went smoothly... What could be the cause? This is bugging me.

btw, Im so sorry!!! I REALLY HOPE I COULD SPREAD REP TO RETURN YOUR FAVOR FOR HELPING ME!!! :( Thank you guys!!! really appreciate it!!!
 
To determine what is causing a disconnection, you should keep track of what is going on when the disconnection happened, and try to replicate it. If you can't replicate it in LAN, then chances are that the disconnection is unrelated to the code. Disconnections can occur when a person's internet hangs.

You'll have to make sure all your code doesn't desync. Keep note of all instances of GetLocalPlayer(). I wrote a tutorial on GetLocalPlayer(), and it may help you get a feel for what the function actually does:
http://www.thehelper.net/threads/jass-getlocalplayer.77369/
I think I could improve the tutorial more, but I haven't touched it in a year. It gets the point across.

If you can find the code that desyncs, post it here.
 
Status
Not open for further replies.
Top