The modding overview wiki page (https://forums.factorio.com/wiki/inde ... g_overview) gives the following snippet as an example, but I can't get it to work. I've tried placing it in control.lua and calling it from the console. Am I missing something obvious?
data.raw.ammo["piercing-bullet-magazine"].magazine_size = 20
Modding help - How do I read/write the data table?
Re: Modding help - How do I read/write the data table?
You need to place it in data.lua, as that file is loaded when the game initializes.
The file control.lua is only run when you start/load a game and I believe it is unable to alter the raw data.
It can also be placed in data-updates.lua or data-final-fixes.lua files, depending on when you want it to be executed.
First all data.lua files are executed, then all data-updates.lua files, then all data-final-fixes.lua files.
I'd recommend re-reading the page you linked, this information is available in the same chapter as the code you specified.
The file control.lua is only run when you start/load a game and I believe it is unable to alter the raw data.
It can also be placed in data-updates.lua or data-final-fixes.lua files, depending on when you want it to be executed.
First all data.lua files are executed, then all data-updates.lua files, then all data-final-fixes.lua files.
I'd recommend re-reading the page you linked, this information is available in the same chapter as the code you specified.
My mods: Red Alert Harvesters - Clean Pipes - Filtered Splitters
Re: Modding help - How do I read/write the data table?
Oh.. is there any way to READ the raw data?
On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
Re: Modding help - How do I read/write the data table?
game.entityprototypes have all entity prototipes.wahming wrote:Oh.. is there any way to READ the raw data?
Or if you have the entity (in onbuildentity for example), can call [entity].prototype, isn't like raw data, but is the best option for now, i think.
i don't know what do that "integer variable", but i think the best way to know about differences with some entities, is the name.wahming wrote:On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
For example, you have 2 belts with the same speed, but change the color, with names "belt-red", "belt-yellow" and "belt-black", you can use game.player.print(string.sub([entity].name,6)) to write the color of entity.
But you can't edit the prototype in the game (data.raw), i don't know what variable is doing, if you need add a number to only 1 entity, like if 1 "belt-red" need know is the number 1, and all other without number, the best way is with a table, you can save the entity in a variable, for example with this, you need: belts = { entity = [entity], number = 1 }.
But i don't know what you need do.
Re: Modding help - How do I read/write the data table?
What operations/methods are available for me on the prototype? I can get the reference to it, but not sure what to do with it.L0771 wrote:game.entityprototypes have all entity prototipes.wahming wrote:Oh.. is there any way to READ the raw data?
Or if you have the entity (in onbuildentity for example), can call [entity].prototype, isn't like raw data, but is the best option for now, i think.
I need to have 1 number for each and every entity that exists in the game, of type "transport-belt". It can be different for each belt. Does that mean I need to create a huge table that contains every single transport belt in-game?L0771 wrote:i don't know what do that "integer variable", but i think the best way to know about differences with some entities, is the name.wahming wrote:On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
For example, you have 2 belts with the same speed, but change the color, with names "belt-red", "belt-yellow" and "belt-black", you can use game.player.print(string.sub([entity].name,6)) to write the color of entity.
But you can't edit the prototype in the game (data.raw), i don't know what variable is doing, if you need add a number to only 1 entity, like if 1 "belt-red" need know is the number 1, and all other without number, the best way is with a table, you can save the entity in a variable, for example with this, you need: belts = { entity = [entity], number = 1 }.
Re: Modding help - How do I read/write the data table?
[entity].prototype.help()wahming wrote:What operations/methods are available for me on the prototype? I can get the reference to it, but not sure what to do with it.L0771 wrote:game.entityprototypes have all entity prototipes.wahming wrote:Oh.. is there any way to READ the raw data?
Or if you have the entity (in onbuildentity for example), can call [entity].prototype, isn't like raw data, but is the best option for now, i think.
I think are these
Is the only way, treefarm have a table with every field and every tree on a field, i have something like 30 fields with... 25 trees everyone? i have more trees than belts, without problem.wahming wrote:I need to have 1 number for each and every entity that exists in the game, of type "transport-belt". It can be different for each belt. Does that mean I need to create a huge table that contains every single transport belt in-game?L0771 wrote:i don't know what do that "integer variable", but i think the best way to know about differences with some entities, is the name.wahming wrote:On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
For example, you have 2 belts with the same speed, but change the color, with names "belt-red", "belt-yellow" and "belt-black", you can use game.player.print(string.sub([entity].name,6)) to write the color of entity.
But you can't edit the prototype in the game (data.raw), i don't know what variable is doing, if you need add a number to only 1 entity, like if 1 "belt-red" need know is the number 1, and all other without number, the best way is with a table, you can save the entity in a variable, for example with this, you need: belts = { entity = [entity], number = 1 }.
With my experience, the only problem is overload the event ontick
Re: Modding help - How do I read/write the data table?
Hmm. Not much info available from there. I wanted to get info like belt speed, for example. Guess it may not be possible.L0771 wrote:[entity].prototype.help()wahming wrote:What operations/methods are available for me on the prototype? I can get the reference to it, but not sure what to do with it.L0771 wrote:game.entityprototypes have all entity prototipes.wahming wrote:Oh.. is there any way to READ the raw data?
Or if you have the entity (in onbuildentity for example), can call [entity].prototype, isn't like raw data, but is the best option for now, i think.
I think are these
Ok, will try that, thanks!L0771 wrote:Is the only way, treefarm have a table with every field and every tree on a field, i have something like 30 fields with... 25 trees everyone? i have more trees than belts, without problem.wahming wrote:I need to have 1 number for each and every entity that exists in the game, of type "transport-belt". It can be different for each belt. Does that mean I need to create a huge table that contains every single transport belt in-game?L0771 wrote:i don't know what do that "integer variable", but i think the best way to know about differences with some entities, is the name.wahming wrote:On a related question - I'm trying to create a custom transport belt, with an additional integer variable. This variable can be different for each instance of the belt, and should be writeable to me. What's the best way for me to do this?
For example, you have 2 belts with the same speed, but change the color, with names "belt-red", "belt-yellow" and "belt-black", you can use game.player.print(string.sub([entity].name,6)) to write the color of entity.
But you can't edit the prototype in the game (data.raw), i don't know what variable is doing, if you need add a number to only 1 entity, like if 1 "belt-red" need know is the number 1, and all other without number, the best way is with a table, you can save the entity in a variable, for example with this, you need: belts = { entity = [entity], number = 1 }.
With my experience, the only problem is overload the event ontick