Page 1 of 1

[RIP]I dont know why this Fails ...

Posted: Sat Dec 10, 2016 11:25 am
by LuziferSenpai
Hey Guys,

I'm working on rewriting all my MODs and than i came in to this Error:

Code: Select all

Error while running event on_built_entity (ID 6)
__SenpaisElectricTrains__/control.lua:45: attempt to get length of field 'Trains' (a nil value)
OLD Code
New Code
Why I rework this?
First to improve some stuff, second to make it much easier to add higher electric locomotives and new locomotives.

Pls help me.

Greetz,

Luzifer

Re: I dont know why this Fails ...

Posted: Sat Dec 10, 2016 11:48 am
by daniel34
Line 45 of control.lua:

Code: Select all

for i = 1, #Senpais.ElectricTrains.Trains do
You are accessing the field Trains, which has not been set before and is therefore nil. Did you maybe mean TrainsList or are you missing a Trains = {}?

Re: I dont know why this Fails ...

Posted: Sat Dec 10, 2016 11:49 am
by LuziferSenpai
daniel34 wrote:Line 45 of control.lua:

Code: Select all

for i = 1, #Senpais.ElectricTrains.Trains do
You are accessing the field Trains, which has not been set before and is therefore nil. Did you maybe mean TrainsList or are you missing a Trains = {}?
I have set it, look in the data.lua ;)

I loaded that in the data.lua for the control.lua ...

Re: I dont know why this Fails ...

Posted: Sat Dec 10, 2016 11:52 am
by daniel34
LuziferSenpai wrote:I have set it, look in the data.lua ;)

I loaded that in the data.lua for the control.lua ...
https://wiki.factorio.com/Lua/Data_Lifecycle
Note that this means there is no game session running (i.e. no global or game state) at the time data-related scripts are executed, and any changes to lua module state will be discarded, preventing them from affecting control.lua.
Variables you set in the data.lua are not available in the control.lua because they are running in separate lua instances.

Re: I dont know why this Fails ...

Posted: Sat Dec 10, 2016 12:00 pm
by LuziferSenpai
daniel34 wrote:
LuziferSenpai wrote:I have set it, look in the data.lua ;)

I loaded that in the data.lua for the control.lua ...
https://wiki.factorio.com/Lua/Data_Lifecycle
Note that this means there is no game session running (i.e. no global or game state) at the time data-related scripts are executed, and any changes to lua module state will be discarded, preventing them from affecting control.lua.
Variables you set in the data.lua are not available in the control.lua because they are running in separate lua instances.
Yeah R.I.P