Its data.lua, probably a typo but i'd rather you getting called out then scratching your head for 30 minutes
atleast to my knowledge anyhow. The info.json and migration files should pretty much be the only jsons.
Control.lua are basically scripts, like if you place down a entity on a sand tile it turns it into something else, i used such a technique to turn sand and dirt into resources, i am yet to utilize them
anyhow, back to data.lua, yes, it is possible. Theres 3 ways of doing it, two of which are better for small changes and the last is good for total overhauls (like when you change everything including the wall of text that is the sprites)
First, for some context ill grab a random entity from the game and remove like 90% of its code to use as an example
Code: Select all
{
type = "assembling-machine",
name = "assembling-machine-2",
blah,blah,blah,
max_health = 250,
blah,blah,
resistances =
{
{
type = "fire",
percent = 70
}
},
blah,blah,blah
},
First way, changing a value. data.raw["Type"]["Name"]["Property"] = new_value
So, if you wanted to change max health to 300 you would use data.raw["assembling-machine"]["assembling-machine-2"][max_health"] = 300
You can dig deeper, say you want to change filename - data.raw["Type"]["Name"]["Property"]["Subproperty"] = new_value
So, to change the fire resistance, it would be like this data.raw["assembling-machine"]["assembling-machine-2"]["resistances"]["fire"]["percent"] = 70
It can go on and on, as long as its a sub property you can dig all you want down.
Its to be noted this will REPLACE the last field with the new value, rather then inserting a new value into the field, this is great for changing speeds, not so much for inserting a new recipe to an existing technology.
Second method is insersion. This is especially useful paired with a migration.lua for changing existing recipes. table.insert(data.raw["Type"]["Name"]["Property"])
Say you want to add a resistance? table.insert(data.raw["assembling-machine"]["assembling-machine-2"]["resistances"],{{type = "poison",percent = 70}})
Note the "," rather then the "=". Other then that they are pretty similar, and act the same way.
Its to be noted this will keep old values, rather then replacing them, great for adding recipes to existing technologies.
Not, it is to be noted for both these processes, don't have a comma at the end of each line and they work outside of data:extend({})
so it would look like
Code: Select all
data.raw["stuff"]
data.raw["morestuff"]
data:extend({extra stuff})
Third and least elegant way is literally copy pasting the base game entity and changing all the values. I used to do this when i started out which was not too long ago actually, it leaves for a really messy file, comments much needed
And as a disclaimer, chances are some of my code won't work, however they should serve as needed as examples.
As a bonus, if you want to make a new thing that is based on another thing, you can cheat and copy the entity and change its values all in a lua file, like so
Code: Select all
ShinyEF2 = util.table.deepcopy(data.raw["furnace"]["electric-furnace"])
ShinyEF2.name = "electric-furnace-2Shiny"
ShinyEF2.icon = "__Shinys_Cross-patch__/graphics/icons/electric-furnace2.png"
ShinyEF2.minable = {mining_time = 1, result = "electric-furnace-2Shiny"}
ShinyEF2.max_health = 300
ShinyEF2.module_specification.module_slots = 4
ShinyEF2.energy_usage = "350kW"
ShinyEF2.crafting_speed = 4
ShinyEF2.animation.filename = "__Shinys_Cross-patch__/graphics/entity/electric-furnace/electric-furnace-base2.png"
The "ShinyEF2" is a variable, if that's the word, think algebra class where 1+x=3, where x is 2, and you were probably thinking "Why would anyone even do that?" well we do that now. hue.
Literally re-wrote all my entity files when i found that one out. You can also use variables as values as long as they are set somewhere before the code needs em, like if you require a filecalled config in the data.lua and set all the values there. Also if you value is a mathematical equation that works too. I sometimes do that when i am too lazy to use a calculator, or if i am scaling items off a multiplier.
As for your last part of your question, i belive that you cannot change the table after it has been created (game bootup) but you can delete and replace an entity using the control.lua when an event is triggered, using code.