- Joined
- Nov 4, 2019
- Messages
- 400
I've been trying to solve the desyncs in my map for almost a month now. I've looked through every trigger and script and I can't find anything suspect but my save/load system and I'm wondering if I'm doing things wrong. I got inspired by TriggerHappy's Codeless save/load system and since I'm writing in Lua I can't import his library (JASS) into my map, so I decided to just look at the code, try to understand it and make my own.
For context, the preloader loads a file that injects code that changes an ability tooltip for the players (locally) but sends the data for the current player in the loop to a synced event so everyone is in sync... is the idea at least. It works, except I think it's causing a desync and I'm sort of blaming the fact that I'm doing this inside a loop, but I'm just not sure.
Lua:
function InitLoad()
local trig = CreateTrigger()
TriggerAddAction(trig, SyncData)
for i = 0, bj_MAX_PLAYER_SLOTS do
BlzTriggerRegisterPlayerSyncEvent(trig, Player(i), "LoadData", false)
end
-- Load all player saves
ForForce(GetPlayersAll(), LoadStrings)
end
function LoadStrings()
local player = GetConvertedPlayerId(GetEnumPlayer())
-- increase when more character slots are created
for i = 1, 3 do
if (player < 24) then
local data = ""
Preloader("\\AzerothRPG\\Hero" .. i .. ".txt")
data = BlzGetAbilityTooltip(1097690227, 0)
BlzSetAbilityTooltip(1097690227, originalTooltip, 0) -- Reset tooltip
if (GetLocalPlayer() == GetEnumPlayer()) then
BlzSendSyncData("LoadData", data)
end
end
end
end
function SyncData()
local player = GetConvertedPlayerId(GetTriggerPlayer())
if (characterNext[player] == nil) then
characterNext[player] = 1
else
characterNext[player] = characterNext[player] + 1
end
characterLoadStrings[player][characterNext[player]] = BlzGetTriggerSyncData()
LoadCharacterForPlayer(player, characterNext[player])
end
For context, the preloader loads a file that injects code that changes an ability tooltip for the players (locally) but sends the data for the current player in the loop to a synced event so everyone is in sync... is the idea at least. It works, except I think it's causing a desync and I'm sort of blaming the fact that I'm doing this inside a loop, but I'm just not sure.
Last edited: