detect if scenario is running / scenario data lifecycle?

Place to get help with not working mods / modding interface.
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 445
Joined: Thu Dec 21, 2017 8:02 am
Contact:

detect if scenario is running / scenario data lifecycle?

Post by ownlyme »

i'm the creator of the mod "wave defense unlimited"
in the last version, i changed it so that the scenario is executed by the mod files instead of the scenario files.
the reason for this was to make it easier to update the mod (before you had to update the control.lua in the savegame, which was a terrible solution)

is it somehow possible to check if a scenario is running or what the ways of transferring data between the scenario and the mod exist?
i tried using a remote interface but that just results in multiplayer problems, at least the way how i did it.
i would even take a solution that doesn't let you migrate existing savegames, but i don't know how i detect a scenario without a remote interface.

https://mods.factorio.com/mod/Wave_Defense_Unlimited

right now i'm pretty much out of ideas.
i would really appreciate your help.
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: detect if scenario is running / scenario data lifecycle?

Post by DaveMcW »

Remote interfaces can be defined and called anywhere. Mod files, scenario files, even the console.

You will have to do one more manual save edit to add the interface for exporting though.

control.lua (scenario)

Code: Select all

remote.add_interface("scenario files", {
  export_global_data = function() return global end,
})
control.lua (mod)

Code: Select all

script.on_init(function()
  if remote.interfaces["scenario files"] then
    global = remote.call("scenario files", "export_global_data")
  end
end)
Remember that global can only be accessed inside script events. And global is the only table you should use for storing data.
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 445
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: detect if scenario is running / scenario data lifecycle?

Post by ownlyme »

i think i got it now.
it even seems to migrate (after updating the control.lua)

wanna take a look and tell me what you think?
i didn't entirely knew what i was doing
the data lifecycle is pretty messy now.
at least it works i guess..
Wave_Defense_Unlimited_0.16.11.zip
(747.62 KiB) Downloaded 86 times
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
Post Reply

Return to “Modding help”