Page 1 of 1

[0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 9:50 am
by MrFreohr
I tried loading 2 differents mods which use an internal lua variable with the same name, and there is a conflict during the game initial loading, the second mod uses the variable from the first mod to load its resources.
In my case, I am currently using the Logistic Train Network mod and the WaiTEX mod
For Logistic Train Network 0.9.11

Code: Select all

MOD_NAME = "LogisticTrainNetwork"
and for WaiTEX 1.2.0

Code: Select all

MOD_NAME = "__WaiTex_Full__"
In this case, the variable name is only used to load graphic resources, and since both mods use a different convention for the graphic resource location the game simply fails to load : LTN does not includes the underscores to specify the mod root in the variable, whereas WaiTex does.

Code: Select all

if wagon.name == "rail-tanker" then
	signal.icon = "__"..MOD_NAME.."__/graphics/icons/rail-tanker.png"
end

VS

stripe = 
{
	filename = MOD_NAME.."/graphics/entity/accumulator/accumulator.png",
	width_in_frames = 1,
	height_in_frames = 1
}
But if the variables from one mod are not constrained to the scope of the mod, it could lead to potential hard to decipher bugs.

I don't think this is a mod bug, since both mods work fine separately, and also together when I edit the LTN mod to hardcode the mod root for the resource loading.

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 9:55 am
by Rseding91
The Lua state is shared between all loaded mods. Mods should not be storing variables in the global scope in the data stage since you get these kinds of errors.

The reason the lua state is shared is so you can edit all previous prototype data.raw from the last loaded mod(s). Otherwise mods couldn't edit anything except their own definitions.

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 10:24 am
by MrFreohr
Thanks for the reply.
It makes sense that mods could alter other mods, without having to import all the code in their own definition.
I'll go write bug reports on those mods threads then, so I can play without having to correct this every update.

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 5:31 pm
by Optera
Guess I'll hardcode paths from now on.
There should be a big warning about this in the modding tutorial and wiki.

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 6:36 pm
by Rseding91
Its' documented here: http://lua-api.factorio.com/latest/Data-Lifecycle.html

We don't control any modding totorial or wiki directly - those are all community driven things so you'll need to contact them.

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Tue Mar 28, 2017 9:15 pm
by Nexela
Optera wrote:Guess I'll hardcode paths from now on.
You don't need to hardcode your paths just uniqueify your variables

For my mods I typically do something like this:

LTN_CONST= {}
LTN_CONST.MOD_NAME = "Logistictrains"

Re: [0.14.22] Variable conflicts when loading different mods

Posted: Wed Mar 29, 2017 6:09 am
by Optera
Nexela wrote:
Optera wrote:Guess I'll hardcode paths from now on.
You don't need to hardcode your paths just uniqueify your variables

For my mods I typically do something like this:

LTN_CONST= {}
LTN_CONST.MOD_NAME = "Logistictrains"
True, but it made me rethink and I came to the conclusion that having variables for paths only makes sense if you plan on changing the mod name a lot.