Page 1 of 1
Mod multiplayer
Posted: Sat May 27, 2017 10:45 pm
by Ranakastrasz
"Cannot Join. The following mod event handlers are not identical between you and the server. This indicates that the following mods are not multiplayer (save/load) safe."
What causes this error in a mod, and how do I fix it?
viewtopic.php?f=144&t=26473
Its kinda irritating, and I didn't change anything.
Re: Mod multiplayer
Posted: Sat May 27, 2017 11:02 pm
by Nexela
You are registering tick in on_init
Conditionally removing tick in the tick handler
not checking on_load to see if the tick handler is registered or not.
Re: Mod multiplayer
Posted: Sat May 27, 2017 11:03 pm
by Nexela
You are also changing it around to things like 0 and nil
Re: Mod multiplayer
Posted: Sat May 27, 2017 11:10 pm
by bobingabout
Long story short, when it comes to variables, only ever do 1 of 2 things.
Everything in global
A constant (varible = value and NEVER change it)
local within a function for temporary variables (calculated the same by every player)
if it doesn't fit one of those things, you're doing it wrong. A recent update changed to error when it detects these issues, rather than just allowing a possible desync.
Re: Mod multiplayer
Posted: Sat May 27, 2017 11:47 pm
by Ranakastrasz
Hmm.
I suppose need to find a more recent mod to copy, since I've been doing that for a long time, given it is how other mods did that.
Re: Mod multiplayer
Posted: Sun May 28, 2017 1:31 am
by Ranakastrasz
Nexela wrote:You are registering tick in on_init
I thought you were supposed to do that?
Conditionally removing tick in the tick handler
Forgot to remove that. IT never runs anyway, since "shouldKeepTicking" cannot change to anything but true. Its an artifact from the mod.. Probably from V11 or something that I copied it from.
Had events to turn the ticker on and off.
not checking on_load to see if the tick handler is registered or not.
I thought you couldn't double-register, and it just overrode it, at least in a single mod. After all, you deregister by setting it to nil, or null, or whichever it is in lua.
The way I understand it now, is that you need to register on game initilization, and on Mod configuration change, which are the two possiblities that can occur. Both run only when the host starts the game.
Could someone point me at how to do this correctly? Its been annoying pretty much since I started modding.
Re: Mod multiplayer
Posted: Sun May 28, 2017 2:20 am
by Nexela
Registering in on_init is fine but that means you are conditionally registering. If you don't want to register conditionally then move your tick registration out of on_init
Code: Select all
on_init
global.ticking = true
register on_tick()
end
on_load
if global.ticking = true then
register on_tick()
end
on_tick
if don't need to tick anymore then
global.ticking = false
de register on_tick()
end
if you don't need a conditional tick handler then just
Code: Select all
on_init
--set up all vars
end
script.on_event(defines.events.on_tick, tick)
http://lua-api.factorio.com/latest/Data-Lifecycle.html
Re: Mod multiplayer
Posted: Mon May 29, 2017 2:14 pm
by Ranakastrasz
Ok, that makes sense.
I think I understand.