why do references into data.raw require both name and type?

Place to get help with not working mods / modding interface.
Post Reply
admo
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 1:07 am
Contact:

why do references into data.raw require both name and type?

Post by admo »

I have lots of programming experience but I am confounded on why I must supply both the type and then name when dereferencing into data.raw. An example from entities.lua:

Code: Select all

  {
    type = "electric-pole",
    name = "big-electric-pole",
    icon = "__base__/graphics/icons/big-electric-pole.png",
    flags = {"placeable-neutral", "player-creation"},
    minable = {hardness = 0.2, mining_time = 0.5, result = "big-electric-pole"},
    max_health = 150,
    corpse = "medium-remnants",
    resistances =
    {
      {
        type = "fire",
        percent = 100
      }
    },
...
Then my modification would access a value via:

Code: Select all

data.raw["electric-pole"]["big-electric-pole"]["max_health"] = 1
Is data.raw some sort of programatically assembled table which doesn't represent the layout above?

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

Re: why do references into data.raw require both name and type?

Post by Rseding91 »

Names are not required to be unique between different types.

For instance: ["item"]["copper-ore"] and ["entity"]["copper-ore"] are 2 different things.
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: why do references into data.raw require both name and type?

Post by bobingabout »

The one I always wondered is why does it data:extend put it in data.raw?

game.variable
settings.variable
script.variable
data.raw.variable

wouldn't it be a better structure to have data[type][name]? The .raw part seems a bit redundant because EVERYTHING is in data.raw.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: why do references into data.raw require both name and type?

Post by darkfrei »

bobingabout wrote:The one I always wondered is why does it data:extend put it in data.raw?
I think it was separated for base mod in raw and all another to new category, but not realized.
Last edited by darkfrei on Fri May 12, 2017 1:06 pm, edited 1 time in total.

admo
Inserter
Inserter
Posts: 27
Joined: Tue Jun 28, 2016 1:07 am
Contact:

Re: why do references into data.raw require both name and type?

Post by admo »

Thank you for the help everyone.

Post Reply

Return to “Modding help”