Mod multiplayer

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Mod multiplayer

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Mod multiplayer

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

Re: Mod multiplayer

Post by Nexela »

You are also changing it around to things like 0 and nil
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod multiplayer

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mod multiplayer

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mod multiplayer

Post 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.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Mod multiplayer

Post 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
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mod multiplayer

Post by Ranakastrasz »

Ok, that makes sense.

I think I understand.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Modding help”