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.
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:
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.
--- Registers a function for a given event. If a nil handler is passed remove all events and stop listening for that event.
-- Events are dispatched in the order they are registered.
-- @usage Event.register(defines.events.on_tick, function(event) print event.tick end)
-- -- creates an event that prints the current tick every tick.
-- @tparam defines.events|{defines.events,...} event events to register
-- @tparam function handler Function to call when event is triggered
-- @treturn Event
function Event.register(event, handler)
fail_if_missing(event, "missing event argument")
event = (type(event) == "table" and event) or {event}
for _, event_id in pairs(event) do
if not (type(event_id) == "number" or type(event_id) == "string") then
error("Invalid Event Id, Must be string or int, or array of strings and/or ints", 2)
end
if handler == nil then
Event._registry[event_id] = nil
script.on_event(event_id, nil)
else
if not Event._registry[event_id] then
Event._registry[event_id] = {}
if type(event_id) == "string" or event_id >= 0 then
script.on_event(event_id, Event.dispatch)
elseif event_id < 0 then
Event.core_events._register(event_id)
end
end
table.insert(Event._registry[event_id], handler)
end
end
return Event
end