How do I find the "what" in data.raw.what?

Place to get help with not working mods / modding interface.
Post Reply
Moosfet
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Fri Jun 10, 2016 1:50 pm
Contact:

How do I find the "what" in data.raw.what?

Post by Moosfet »

So in the only Factorio modding tutorial that seems to exist, they make a new armor like this:

Code: Select all

local fireArmor = table.deepcopy(data.raw["armor"]["heavy-armor"])
This only seems to work with armor though. At first I tried changing it to this:

Code: Select all

local flip_dot = table.deepcopy(data.raw["lamp"]["small-lamp"])
...but that gave me some error which led to a bunch of search results that were from other people attempting to follow this tutorial. It seems like the links point somewhere else today, but yesterday one of them went to a page where you could find "heavy-armor" in a group named "armor," and you could also find "small-lamp" in a group named "lamp," and other things people were trying on the internet and resulting in the same error. IDK why but today none of the links seem to point to the same page I was looking at yesterday so I can't link it.

Eventually I figured out I can do this:

local flip_dot = table.deepcopy(data.raw.lamp["small-lamp"])

Why I have to do this for the small-lamp, but the previous code works for the armor, I have no idea. ...but it worked, so I went with it.

Today I want to do similarly with the power switch, but I don't know which data.raw.what to copy it from. I tried data.raw.power-switch["power-switch"] and data.raw.switch["power-switch"] and everything else I could think of but no luck guessing it.

Is there some place I can look up stuff like this? Unfortunately that tutorial only goes as far explaining how to copy the character as well. It doesn't say what to copy anything else from and it doesn't say how to find out.

Also, are there any better tutorials? I'm so frustrated with having to guess how to do things that I'm about to give up and delete all the files.

Also, if anyone has any clever ideas how to implement a flip dot, I wouldn't mind hearing them. I made one out of the lamp, but the lamp can't be animated, so now I'm trying to make one out of the power switch, but I don't know that the power switch can be made smaller, and I don't know that I can actually remove that glowing animation it has when it's turned on, as with my attempt at just copying the whole entity definition from the game files, the game refused to get past the point where I didn't want to specify a sparkly animation.

I made some nice graphics for it, which took a while because there also seems to be no documentation of how graphics should be rendered for the game, so I had to guess all the parameters and keep changing them until the thing lined up on the screen correctly.
hr-box.png
hr-box.png (15.17 KiB) Viewed 863 times
flip-dot-animation.png
flip-dot-animation.png (15.51 KiB) Viewed 863 times
flipscreenshot.png
flipscreenshot.png (110.53 KiB) Viewed 863 times
Having to guess at things is so frustrating.

Xorimuth
Filter Inserter
Filter Inserter
Posts: 625
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: How do I find the "what" in data.raw.what?

Post by Xorimuth »

Moosfet wrote:
Fri Sep 16, 2022 10:11 pm
So in the only Factorio modding tutorial that seems to exist, they make a new armor like this:

Code: Select all

local fireArmor = table.deepcopy(data.raw["armor"]["heavy-armor"])
This only seems to work with armor though. At first I tried changing it to this:

Code: Select all

local flip_dot = table.deepcopy(data.raw["lamp"]["small-lamp"])
...but that gave me some error which led to a bunch of search results that were from other people attempting to follow this tutorial. It seems like the links point somewhere else today, but yesterday one of them went to a page where you could find "heavy-armor" in a group named "armor," and you could also find "small-lamp" in a group named "lamp," and other things people were trying on the internet and resulting in the same error. IDK why but today none of the links seem to point to the same page I was looking at yesterday so I can't link it.

Eventually I figured out I can do this:

local flip_dot = table.deepcopy(data.raw.lamp["small-lamp"])

Why I have to do this for the small-lamp, but the previous code works for the armor, I have no idea. ...but it worked, so I went with it.

Today I want to do similarly with the power switch, but I don't know which data.raw.what to copy it from. I tried data.raw.power-switch["power-switch"] and data.raw.switch["power-switch"] and everything else I could think of but no luck guessing it.

Is there some place I can look up stuff like this? Unfortunately that tutorial only goes as far explaining how to copy the character as well. It doesn't say what to copy anything else from and it doesn't say how to find out.

Also, are there any better tutorials? I'm so frustrated with having to guess how to do things that I'm about to give up and delete all the files.
I'd highly recommend the #mod-making channel on the factorio discord if you've got modding questions.

The reason you are struggling to find answers is that it is a lua question, not a factorio question. You can find the entire lua reference here (https://www.lua.org/manual/5.2/manual.html), it isn't very long!

`data.raw` is just a table of tables, there's nothing fancy about it. It is indexed first by type (e.g. "lamp", "armor"), then by prototype name (e.g. "heavy-armor", "small-lamp"). In lua, you access a table like this: `mytable["mykey"]`. But, there's some syntax 'sugar' to make it look nicer, so you can also do it as `mytable.mykey`. This doesn't work if mykey has hyphens in though (if it does you have to use the first method).

So: `data.raw["armor"]["heavy-armor"]` is exactly the same as `data.raw.armor["heavy-armor"]`, and `data.raw["lamp"]["small-lamp"]` is exactly the same as `data.raw.lamp["small-lamp"]`. Your example that you said gave an error is perfectly correct, if there was an error it would be from something else.

For power switches, you can't just do `data.raw.power-switch["power-switch"]`, since it has a hyphen in, so you have to do `data.raw["power-switch"]["power-switch"]`.

And you can find all of the type names here: https://wiki.factorio.com/Prototype_definitions
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

Moosfet
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Fri Jun 10, 2016 1:50 pm
Contact:

Re: How do I find the "what" in data.raw.what?

Post by Moosfet »

Thanks. I got it to work. :)

flipdot.mp4
(463.95 KiB) Downloaded 66 times
flip-dots_0.0.2.zip
(235.07 KiB) Downloaded 61 times

Post Reply

Return to “Modding help”