[lua] [desync] map desyncs

Level 5
Joined
Oct 29, 2024
Messages
27
Can anyone help me with a desync?
I removed almost anything that happens in my map (no automatic triggers run any code, and most of the main thread code also gone).
My main thread reaches what I changed (for debugging the desync) to an endless loop:

Lua:
while true do
    TriggerSleepAction(0.25)
end

If I remove this loop and let the thread die, no desync happens.
If I leave the loop and create units over and over again (with a chat trigger I have that creates many units), after about 10 minutes of my heroes attacking those new unit one of the 2 players desyncs
 
Level 14
Joined
Jan 10, 2023
Messages
243
You realize we have no context and you are asking us why if you use wait in an infinite loop to achieve nothing other than more waiting it causes a desync, but if you don't do that it doesn't.
I'm hoping and assuming that there is more to your loop than this and that this is only an example, but if this is the whole loop, it's likely desyncing in 10 minutes because you've given both players an infinite loop in slow-motion and eventually they get crossed... I don't think anyone can help you with so little context, but that's my shot in the dark.
 
Level 5
Joined
Oct 29, 2024
Messages
27
You realize we have no context and you are asking us why if you use wait in an infinite loop to achieve nothing other than more waiting it causes a desync, but if you don't do that it doesn't.
I'm hoping and assuming that there is more to your loop than this and that this is only an example, but if this is the whole loop, it's likely desyncing in 10 minutes because you've given both players an infinite loop in slow-motion and eventually they get crossed... I don't think anyone can help you with so little context, but that's my shot in the dark.
The original loop is creating units, and stops running when some point is reached in another context, but trying to debug what the issue was, I removed those things and saw that the desync still happens.
What do you mean that they eventually get crossed? Do you mean that there is a small chance to desync every time TSA is used, and since it's used many times in a loop, at some time it just happens?
Lua using TriggerSleepAction(), that defeats the purpose!
Well, this is a JASS map I'm trying to convert to Lua... There are a lot of TSA there already sadly
 
Last edited:
Level 14
Joined
Jan 10, 2023
Messages
243
What do you mean that they eventually get crossed? Do you mean that there is a small chance to desync every time TSA is used, and since it's used many times in a loop, at some time it just happens?

I'm really just spitballing because I don't have any context. Even the context you've now provided is not enough (for me at least, but unless someone corrects me, I would think this is still not enough).

I'm not sure what other causing might bring a desync, but chiefly they are caused because two clients disagree about data they are supposed to be in lockstep on (I'm guessing you know that, just explaining myself).
Because it seemed to me that you gave little context, and because I am a bored aging man with little better to do other than skim for unhelped patrons on the Hive, I decided to point out that their was no context and made this suggestion as a gesture of good faith, so you would think I wasn't just some jerk trying to get one up on you.

That being said, my theory was that this trigger was running indefinitely, and likely this trigger would fire again and then be firing multiple times indefinitely, and therefore as lag built the likelihood for timing discrepancies might grow and ultimately result in a desync.

Mostly I was trying to poke you.

I see a lot of people being very discrete about their work on the Hive, but I have never seen someone steal someone else's work unnoticed and I have never seen someone make it rich on WC3 mapping efforts, so I don't think you would be crazy to help us help you and just share the trigger...

But I suppose it may be that you have other reasons, such as not wanting to muddy the water of this discussion with unnecessary details.

PS: @Uncle I'm curious, are waits necessary in JASS? I can't remember if I've used them, but I tend to prefer timers anyway, because for some time I wasn't sure why triggersleepaction was troublesome so I learned to avoid it.
 
Level 44
Joined
Feb 27, 2007
Messages
5,474
I'm curious, are waits necessary in JASS? I can't remember if I've used them, but I tend to prefer timers anyway, because for some time I wasn't sure why triggersleepaction was troublesome so I learned to avoid it.
Can you define what you mean by "necessary"? They are a handy convenience tool for normal mapmaking because TSA preserves many event responses, but running a timer callback function won't have those event responses. Also GUI has no direct access to functions outside of the map CS section, so the way timers are handled in GUI is kind of annoying and convoluted if you know what is going on under the hood. It's just a hassle save for things that don't need to be precise.
 
Level 14
Joined
Jan 10, 2023
Messages
243
Can you define what you mean by "necessary"?
Poor choice of words on my part.

You have answered my intended question which was "do they serve any purpose?" which I now wish I took the time to pose correctly because it seems obvious now and I've even used it for that convenience.

Ironically, that's not even my underlying question.

TSA's have no place in Lua?
That's my real question, but that being said, I can generally read-ish Lua, but I haven't used it and don't expect a full education here, but I thought that they were more or less serving the same purpose in wc3 and working out to effectively the same outcome, only I thought that Lua was more refined and would be eventually the only supported script.... but I'm sure my lack of knowledge is showing.

Anyway, I would think that so long as triggers are used, TSAs would have purpose at least in convenience for event response natives, but does Lua have another function than TSA it uses or something?
 
Level 44
Joined
Feb 27, 2007
Messages
5,474
I don't know more than you about WC3 Lua, but I think the implication is just that defining a local function inside of the current scope to use as your timer callback is extremely simple in Lua because it doesn't break your code flow. These are not real words and I'm not a real programmer. Something like:
Lua:
TimerStart(NewTimer(), false, 30.2, function {
  BJDebugMsg("Timer callback 30.2s later!")
})
And I think they can be passed arguments too.
 
Last edited:
Level 28
Joined
Sep 26, 2009
Messages
2,545
I would not be surprised if infinite loop caused some kind of thread crash after X minutes for some clients which lead to desync.
Or if it was some issue with lua GC incorrectly cleaning up some data used in function that runs the loop which lead to desync (considering how many gc-related issues we have with lua in wc3 :D ).

@Tomotz I think you should just refactor your code so that instead of infinite loop with wait inside you should use timers with callbacks, like how Pyro showed in his post above.
 
Level 14
Joined
Jan 10, 2023
Messages
243
O, I see, and you're right about arguments. I did a quick search and found many examples of passing arguments through callbacks.

Maybe I should learn some Lua, that does sound useful, at least I could avoid dedicating a global variable in such a case.
But JASS is just so lovely to read lol I feel like I'm coding in essay form with it.
 

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
O, I see, and you're right about arguments. I did a quick search and found many examples of passing arguments through callbacks.

Maybe I should learn some Lua, that does sound useful, at least I could avoid dedicating a global variable in such a case.
But JASS is just so lovely to read lol I feel like I'm coding in essay form with it.
vJASS:
function Demo takes integer i returns string s
    return I2S(i)
endfunction
Lua:
function Demo(i)
    return I2S(i)
end
^ Come on, that's clean!

Anyway, I was just implying that Lua has nicer options, coroutines for example. Plus libraries designed around convenience (see Bribe's Lua infused GUI), it's far less limited. But you can use TriggerSleepAction() in either, it's not a big deal depending on the situation.

Also, you don't even really need to learn much when it comes to Lua, you're using the same Warcraft 3 API. Lua basically has less requirements, less syntax, etc. It's very easy to learn how to stop using the words "takes", "returns", "set", "call" for example, since it just feels more natural to begin with.

But this is very off-topic, lol... @Tomotz you should try it without using Waits (TriggerSleep)
 
Last edited:

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
Yeah, when I change this specific TSA to Timer the problem is solved, but the map is full of TSA. And seemingly full of desync causes after the Lua conversion.
I'm very close to just letting go of the move to Lua and staying in JASS.
It will be very sad though since Lua is so much more fun
Not sure if this still works, if it ever worked, or if it's maintained, but if your map is mostly GUI then it could be a game changer:

Not sure if this is already included in Lua Infused GUI, but it seems extra useful for you:
 
Level 14
Joined
Jan 10, 2023
Messages
243
Come on, that's clean!

Anyway, I was just implying that Lua has nicer options, coroutines for example. Plus libraries designed around convenience (see Bribe's Lua infused GUI), it's far less limited. But you can use TriggerSleepAction() in either, it's not a big deal depending on the situation.

Also, you don't even really need to learn much when it comes to Lua, you're using the same Warcraft 3 API. Lua basically has less requirements, less syntax, etc. It's very easy to learn how to stop using the words "takes", "returns", "set", "call" for example, since it just feels more natural to begin with.
Thank you for clarifying and I can't deny, you made some good points to me about Lua and usually I've been telling myself that I don't have the time and JASS was only so worth it because it was so easy for me to read it, but JASS was also my first scripting language and basically my intro to code (TY Hive!) and things are a little different now.

But this is very off-topic, lol...
Thanks for bearing with me @Tomotz and sorry for the scrolling and distraction.
 
Top