LUA warnings on older mods

Place to get help with not working mods / modding interface.
thekabal
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 28, 2025 11:38 am
Contact:

LUA warnings on older mods

Post by thekabal »

I'm working to update older mods for 2.1, and have found a number of instances of warnings in luacheck like:

mutating non-standard global variable data
accessing undefined variable data

In both cases, the relevant lines look like:


data.raw["cargo-pod"]["cargo-pod"].created_effect = {
...
data:extend({

My understanding of Lua leads me to think that these mods are referencing the global variable "data", and changing the code to directly reference global variables clears the error:


_G.data.raw
...
_G.data.extend


But it feels incorrect to do everything in globals directly. I read https://lua-api.factorio.com/latest/aux ... orage.html and I'm wondering if I could instead shift these mods to use the storage variable instead? Would that be better? What would that look like?
robot256
Smart Inserter
Smart Inserter
Posts: 1434
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: LUA warnings on older mods

Post by robot256 »

data.raw and data:extend always (and only) exist in the Data stage during game startup. They are defined by the game engine before the mod's data.lua runs inside the shared Data stage Lua context, and persist while base and all mods run data.lua, data-updates.lua, and data-final-fixes.lua. Luacheck is giving you false warning because it doesn't know that. The code is correct and changing it to _G.data would just add clutter.

storage only exists during the Control stage, in the per-mod runtime sandbox context. It is defined by the game engine when the mod's runtime context is created for control.lua. It is not correct to use storage during the Data stage.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
thekabal
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 28, 2025 11:38 am
Contact:

Re: LUA warnings on older mods

Post by thekabal »

Fantastic detail and explanation! Thank you very much!
Post Reply

Return to “Modding help”