Page 1 of 1
How to track down desyncs?
Posted: Fri Aug 05, 2016 5:41 am
by Optera
My mod, Inventory Sensor, keeps desyncing almost instantly. How do I find out what's causing these desyncs?
Re: How to track down desyncs?
Posted: Fri Aug 05, 2016 6:10 am
by Adil
By staring intensively at the code, and by making lucky guesses.
You define a variable `ticks`which is local to the particular instance of control.lua and then modify it. Whereas second player has this variable initiated to 0 in his instance of the code when he connects. Thus a single variable has different values.
You should put this variable in `global` table. All non-constants should be stored in global.
Re: How to track down desyncs?
Posted: Fri Aug 05, 2016 6:14 am
by Optera
Thanks a lot, changing ticks to global fixed it.
Is there some entry about local vs global variables I missed on the modding tutorial?
Re: How to track down desyncs?
Posted: Fri Aug 05, 2016 6:28 am
by Adil
Well, I don't know which tutorial is mentioned, but on the matter:
All non-constants should be stored in global.
If you set any value based on some state of your game, it makes no sense not to store that value in a table, that preserves the script state over save-loading process.
To clarify:
Everywhere in this thread by global I meant the special table named so. As in, global.ticks, global.ItemSensors and so on. Not just a variable, that is defined without keyword `local` next to it.
Re: How to track down desyncs?
Posted: Fri Aug 05, 2016 6:39 am
by Optera
Now that I think about it from that perspective it makes sense putting not only data that needs to be saved but also variables like timers that need to be synced in global.
I am too used avoiding global variables from c# development.
Perhaps a note in
Lua/Data_Lifecycle Global about local not being synced would make that clear.