[0.14.22] Variable conflicts when loading different mods

Bugs that are actually features.
MrFreohr
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Mar 06, 2016 4:18 pm
Contact:

[0.14.22] Variable conflicts when loading different mods

Post 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.
Attachments
factorio-current.log
factorio_current.log with the mod error
(13.21 KiB) Downloaded 135 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 14138
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

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

MrFreohr
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun Mar 06, 2016 4:18 pm
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

Post 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.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

Post by Optera »

Guess I'll hardcode paths from now on.
There should be a big warning about this in the modding tutorial and wiki.

Rseding91
Factorio Staff
Factorio Staff
Posts: 14138
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

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

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

Post 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"

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14.22] Variable conflicts when loading different mods

Post 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.

Post Reply

Return to “Not a bug”