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

Place to get help with not working mods / modding interface.
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 393
Joined: Tue Jul 08, 2014 10:06 am
Contact:

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

Post 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
Last edited by LuziferSenpai on Sat Dec 10, 2016 12:01 pm, edited 1 time in total.
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: I dont know why this Fails ...

Post 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 = {}?
quick links: log file | graphical issues | wiki
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 393
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: I dont know why this Fails ...

Post 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 ...
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: I dont know why this Fails ...

Post 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.
quick links: log file | graphical issues | wiki
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 393
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: I dont know why this Fails ...

Post 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
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
Post Reply

Return to “Modding help”