Page 1 of 1

[0.15.19] Issue with mod's global table and remote interface

Posted: Sun Jun 11, 2017 6:44 pm
by orzelek
I seem to have a problem with global table not being updated properly when changes are made from remote interface call.
Steps to reproduce:
1. Grab the attached rso mod
2. Crate new game
3. Execute this command:

Code: Select all

/c remote.call("RSO", "disableChunkHandler")
4. Save the game

5. Load the game and check the log

In log file you should see that in step 3 there is an output that says that disableEventHandler has been set to true - it's displaying it directly from global.disableEventHandler.
And yet when loading game you'll see that global level check that prints value of global.disableEventHandler will show that it's null.

My assumption would be that when set to true in remote call value of global.disableEventHandler should be persisted and stored in the save file along with global table. Is that a wrong assumption?

Re: [0.15.19] Issue with mod's global table and remote interface

Posted: Sun Jun 11, 2017 7:08 pm
by Rseding91
The RSO mod is written incorrectly. It's trying to use the variable from the global table before it's even loaded.

Code: Select all

if global.disableEventHandler ~= nil then
	log("disableEventHandler is "..tostring(global.disableEventHandler))
else
	log("disableEventHandler is null")
end

if not global.disableEventHandler then
	log("Adding event handler global")
	script.on_event(defines.events.on_chunk_generated, localGenerateChunk)
end
The control.lua file is parsed and executed to build all function definitions and then the global table is loaded into the Lua instance. That bit of code is run during the parsing before the global table is loaded and so it always reports nil. You'll need to contact the RSO mod developer and have him fix his mod.

Moving all of that logic into the on_load and on_init events would fix it.

Re: [0.15.19] Issue with mod's global table and remote interface

Posted: Sun Jun 11, 2017 11:57 pm
by orzelek
So I can actually run the event check and add the event based on global flag in on_load and it won't cause issues?

Re: [0.15.19] Issue with mod's global table and remote interface

Posted: Mon Jun 12, 2017 3:51 am
by Rseding91
orzelek wrote:So I can actually run the event check and add the event based on global flag in on_load and it won't cause issues?
Yep. That's how I do it: https://github.com/Rseding91/Explosive- ... ol.lua#L57

Re: [0.15.19] Issue with mod's global table and remote interface

Posted: Mon Jun 12, 2017 7:06 am
by orzelek
Thansk for the info.

One more related question:
What will happen if mod that loads before RSO will call the remote interface and I'll try to set variable in global?

Or the mod in question will not see the remote at all at that point since it's loaded only after control.lua is processed?

Re: [0.15.19] Issue with mod's global table and remote interface

Posted: Mon Jun 12, 2017 7:28 am
by Rseding91
orzelek wrote:Thansk for the info.

One more related question:
What will happen if mod that loads before RSO will call the remote interface and I'll try to set variable in global?

Or the mod in question will not see the remote at all at that point since it's loaded only after control.lua is processed?
Unless the mod also does the call wrong it will call it on_load (or during some other event) at which point the global table has already been loaded for RSO.