Page 1 of 1

detect if scenario is running / scenario data lifecycle?

Posted: Mon Aug 27, 2018 9:42 pm
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.

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

Posted: Mon Aug 27, 2018 10:11 pm
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.

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

Posted: Mon Aug 27, 2018 10:30 pm
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 87 times