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

Place to get help with not working mods / modding interface.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

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

Post 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?
Attachments
rso-mod_3.3.8.zip
(43.36 KiB) Downloaded 76 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 16017
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

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

Post 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?
Rseding91
Factorio Staff
Factorio Staff
Posts: 16017
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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
If you want to get ahold of me I'm almost always on Discord.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

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

Post 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?
Rseding91
Factorio Staff
Factorio Staff
Posts: 16017
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”