How to track down desyncs?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

How to track down desyncs?

Post by Optera »

My mod, Inventory Sensor, keeps desyncing almost instantly. How do I find out what's causing these desyncs?
Last edited by Optera on Fri Aug 05, 2016 6:15 am, edited 1 time in total.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: How to track down desyncs?

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: How to track down desyncs?

Post 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?

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: How to track down desyncs?

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: How to track down desyncs?

Post 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.

Post Reply

Return to “Modding help”