[JASS] Mass Data Sync?

Level 31
Joined
Jul 10, 2007
Messages
6,306
I made an interesting test script... I'm wondering what would happen if it were run : )

JASS:
struct tester extends array
    private static string array playing
    private static gamecache gc
    
    private static method test takes nothing returns nothing
        local integer i = 11
        
        set gc = InitGameCache("hello")
        set playing[GetPlayerId(GetLocalPlayer())] = "t"
        call StoreString(tester.syncer, "data", I2S(GetPlayerId(GetLocalPlayer())), "t")
        
        call TriggerSyncStart()
        call SyncStoredString(tester.syncer, "data", I2S(GetPlayerId(GetLocalPlayer())))
        call TriggerSyncReady()
        
        loop
            if (playing[i] != null) then
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(i)) + " is playing")
            endif
            exitwhen i == 0
            set i = i - 1
        endloop
    endmethod
    
    private static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(), 0, false, function thistype.test)
    endmethod
endstruct

Will all of the syncs run or will it stop when it gets a sync?

o-o


I'd test it myself, but I can't test it solo and I don't have any friends online to test with, so I'm stuck ^_^. Nobody ever joins a game hosted for testing something anymore.
 

Bribe

Code Moderator
Level 44
Joined
Sep 26, 2009
Messages
8,965
JASS:
struct tester extends array
    private static method onInit takes nothing returns nothing
        local integer i = 11
        local boolean array playing
        set playing[GetPlayerId(GetLocalPlayer())] = true
        
        call TriggerSleepAction(0.)
        
        loop
            if (playing[i]) then
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(i)) + " is playing")
            endif
            exitwhen i == 0
            set i = i - 1
        endloop
    endmethod
endstruct

The above works because struct initialization is done via ExecuteFunc, so each has its own thread.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306

Bribe

Code Moderator
Level 44
Joined
Sep 26, 2009
Messages
8,965
I actually highly doubt my method would work. I believe it would show for each player that only one player is playing. But I am not sure what you are trying to accomplish by syncing something that has nothing to do with the variable you set, unless somehow you are taking advantage of that "strings get stored to a table" nonsense that blizzard STUPIDLY implemented.
 
Last edited:

Bribe

Code Moderator
Level 44
Joined
Sep 26, 2009
Messages
8,965
I want to make sure I understand what it is you're doing.

set playing[GetPlayerId(GetLocalPlayer())] = true

Right out of the box, each player is only going to have one variable set for his/herself.

What you want to do is sync the variable so all players' local data merges into one? My way will almost certainly not do that.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
It's probably not worth your time examining how blizzard sync natives work; I doubt they even work as they were originally intended, the only useful trait about them is tracking the host-player and it doesn't even work 100% of the time.

A real sync native should sync the values of all the players to that of the host, not simply the first person that is pinged. That doesn't even make any sense for a sync native it's too random. Your time is best spent in more established areas of the World Editor.
 
Top