Page 1 of 1

Mod issue - desync in MP

Posted: Sun Aug 06, 2017 9:42 pm
by TheSAguy
Hi,

I've had a report that my mod was causing desync in MP games.
I can't test this and was hoping I could get the community to help me out with this.

The only change I made was to move my Artifact Collector from another mod to this mod. I also made some functions 'local' functions.
I did not have any issues like this before, so the obvious culprit would be the Artifact Collector stuff.

Again, I'd appropriate it if someone could please help me test this, since I don't do MP myself.
I've attached the mod.

Thanks!

Re: Mod issue - desync in MP

Posted: Sun Aug 06, 2017 9:53 pm
by Klonan
TheSAguy wrote:Hi,

I've had a report that my mod was causing desync in MP games.
I can't test this and was hoping I could get the community to help me out with this.

The only change I made was to move my Artifact Collector from another mod to this mod. I also made some functions 'local' functions.
I did not have any issues like this before, so the obvious culprit would be the Artifact Collector stuff.

Again, I'd appropriate it if someone could please help me test this, since I don't do MP myself.
I've attached the mod.

Thanks!
Your variables here:

Code: Select all

if not NE_Buildings_Config then NE_Buildings_Config = {} end
if not NE_Buildings_Config.mod then NE_Buildings_Config.mod = {} end

if not NE_Buildings then NE_Buildings = {} end
if not NE_Buildings.Settings then NE_Buildings.Settings = {} end
They should be global

Re: Mod issue - desync in MP

Posted: Sun Aug 06, 2017 11:21 pm
by Nexela
You are mixing stdlibs event system with factorios event system.

Event.register is registing on_tick to one thing, and script.on_event is registering on_tick to something else and has conditionals. Pick one system to use, And I recomend against using conditional registration for on_tick for now due to the complexity. Only 1 function can be registered per event, stdlib adds an iteration layer in between. Event.register is ok to use but when using it you loose a lot of the protections built into script.on_event


Secondly you are storing stuff in non global as per Klonans post but the problem goes slightly deeper. If any of those settings you are saving into them get changed you don't have an on_mod_settings_changed events to update them....

Re: Mod issue - desync in MP

Posted: Mon Aug 07, 2017 4:09 am
by TheSAguy
Thanks Klonan and Nexela for looking at my mod.
I think I've made the needed changes.

Made the settings stuff global.
I changed to stdlibs for on_tick:
I changed:

Code: Select all

		script.on_event(defines.events.on_tick, function(event) ticker(event.tick) end)
to

Code: Select all

		Event.register(defines.events.on_tick, function(event)	
			ticker(event.tick)
		end)
I changed:

Code: Select all

script.on_event(defines.events.on_tick, nil)
to

Code: Select all

Event.register(defines.events.on_tick, nil)
Can someone please explain the above two functions to me. Why have anything at all if have the 'nil' there? I would like to understand the function of this.

Is there anything I've missed?
Thanks again!

Re: Mod issue - desync in MP

Posted: Mon Aug 07, 2017 4:40 am
by darkfrei
The second one is from stdlib stdlib/event/
event.lua