Page 1 of 1

How a mod can support both factorio 0.16 and 0.17

Posted: Fri Aug 02, 2019 11:57 am
by NovaM
Hello,

I search a way to detect the factorio base version at runtime.
For sample in data.lua

Code: Select all

local factorio_version = "0.16.51" -- HERE: how to get this version string !

local factorio_major_version = factorio_version:sub(1,4)

if factorio_major_version == "0.16" then
    data:extend({
      ...CODE FOR 0.16...
    }
elseif factorio_major_version == "0.17" then
    data:extend({
      ...CODE FOR 0.17...
    }
else
     ...RAISE AN ERROR, NOT COMPATIBLE...
end
My need is how to get the factorio version string at runtime, during the data.lua step ?

Regards,

Re: How a mod can support both factorio 0.16 and 0.17

Posted: Fri Aug 02, 2019 12:03 pm
by DaveMcW

Code: Select all

local factorio_version = game.active_mods["base"]

Re: How a mod can support both factorio 0.16 and 0.17

Posted: Fri Aug 02, 2019 4:22 pm
by NovaM
Thanks for your answer even it does not run at the data.lua step.
I read again the doc https://lua-api.factorio.com/latest/Data-Lifecycle.html
I wrote a test mod and get the base version from the mods["base"].

Code: Select all

local factorion_version = mods["base"]
the mods["base"] is available at the steps:
- settings.lua, settings-updates.lua, settings-final-fixes.lua
- data.lua, data-updates.lua, data-final-fixes.lua
but not at the control.lua step.

I don't found the way to get the base version at the control step, but it is not my primary need for now.

Regards,