How to reference entries in data.raw? (locomotive)

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Krayt
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Fri Aug 14, 2015 8:47 am
Contact:

How to reference entries in data.raw? (locomotive)

Post by Krayt »

Hello,

Currently I want to continue making some Factorio mods of minor complexity after having not made a Factorio mod for a year or so. Back then when I made my first small Factorio mods I used to manually copy the existing entries within the *.lua files in the folder "prototypes" and then make some changes to the properties.

This time I used the following tutorial to get back to modding: https://wiki.factorio.com/User:Gangsir/ ... e_creation

In the tutorial a "deepcopy" of an existing data-entry is assigned to a local variable. When trying to start Factorio using the newly created "mod" without real functionality, I am getting the following error:
Error loading mods wrote:

Code: Select all

Failed to load mods: __ArmoredTrain__/data.lua:1: __ArmoredTrain__/prototypes/item.lua:3: attempt to index local 'armoredTrain' (a nil value)
The source code of my mod's item.lua:
item.lua
As far as I understand the situation is comparable to what would be a NullPointerException in Java. So I assume my reference to the "diesel-locomotive" in data.raw is not correct. That's why I can't access attributes of my local variable armoredTrain.

So far my google searches using various search terms didn't get me any further.

It would be good, if some modder (or other user) on the forums could point me to the right direction like a current overview about how and where to access entries in data.raw .

Thanks in advance,

Krayt
Last edited by Krayt on Sat May 13, 2017 8:14 pm, edited 1 time in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to reference entries in data.raw?

Post by prg »

Have a look at data/base/prototypes/item/item.lua. "diesel-locomotive" got renamed to just "locomotive".
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

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

Re: How to reference entries in data.raw?

Post by daniel34 »

You are using old code to copy the locomotive, the proper code would be

Code: Select all

local xyz = table.deepcopy(data.raw["item-with-entity-data"]["locomotive"])
The "item-with-entity-data" was implemented in 0.13 I think and the (diesel) locomotive was renamed to just "locomotive" in 0.15.

You can use the *.lua files in the prototypes folder to check what the type/name is supposed to be.
quick links: log file | graphical issues | wiki

User avatar
Krayt
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Fri Aug 14, 2015 8:47 am
Contact:

Re: How to reference entries in data.raw?

Post by Krayt »

prg wrote:Have a look at data/base/prototypes/item/item.lua. "diesel-locomotive" got renamed to just "locomotive".
Thank you. Probably I was confused by outdated information on the internet and the fact that the image names etc. still are "diesel-locomotive[...]". Furthermore I had used the wrong type instead of "item-with-entity-data".
Just to have the working code here for future searchers:

Code: Select all

local armoredTrain = table.deepcopy(data.raw["item-with-entity-data"]["locomotive"])

armoredTrain["name"] = "armored-train"
armoredTrain["order"] = "a[train-system]-g[diesel-locomotive]"
armoredTrain["place_result"] = "locomotive"
armoredTrain["stack_size"] = 5

local recipe = table.deepcopy(data.raw["recipe"]["locomotive"])

recipe.enabled = true
recipe.ingredients = {{"locomotive", 2}, {"steel-plate", 200}}
recipe.result = "armored-train"

data:extend({armoredTrain, recipe})
Greetings,

Krayt

//Edit: And daniel thank you too.

Post Reply

Return to “Modding help”