Page 1 of 1

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

Posted: Fri May 12, 2017 2:51 am
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?

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

Posted: Fri May 12, 2017 3:16 am
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.

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

Posted: Fri May 12, 2017 7:53 am
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.

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

Posted: Fri May 12, 2017 10:35 am
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.

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

Posted: Fri May 12, 2017 11:01 am
by admo
Thank you for the help everyone.