Mod issue - desync in MP

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Mod issue - desync in MP

Post 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!
Attachments
Natural_Evolution_Buildings_7.2.2.zip
NE Buildings
(2.44 MiB) Downloaded 93 times
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Mod issue - desync in MP

Post 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
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Mod issue - desync in MP

Post 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....
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Mod issue - desync in MP

Post 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!
Attachments
Natural_Evolution_Buildings_7.2.3.zip
Updated Mod
(2.44 MiB) Downloaded 88 times
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Mod issue - desync in MP

Post by darkfrei »

The second one is from stdlib stdlib/event/
event.lua
Post Reply

Return to “Modding help”