Prototypes creation

Place to get help with not working mods / modding interface.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Prototypes creation

Post by orzelek »

I have a question about creation of prototypes.
According to wiki we should use the data:extend method as preferred solution - I see small drawback in it for objects that have a lot of attributes.

Will I run into any trouble using the old assignment method with code like this:

Code: Select all

towerCopy = deepCopy(data.raw["ammo-turret"]["gun-turret"])
towerCopy.max_health = 500
towerCopy.name = "gun-turret-1"
towerCopy.minable.result = "gun-turret-1"
data.raw["ammo-turret"]["gun-turret-1"] = towerCopy
Using this way I can easily create nice group of objects/techs(for example few tech levels of similar items).
Only thing that would need to be added separately are the object names/descriptions for locale.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Prototypes creation

Post by prg »

I think it still needs to go through data:extend, try making the last line

Code: Select all

data:extend({towerCopy})
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prototypes creation

Post by orzelek »

I tired it and it works without problems.

I'm simply not sure what might be the risks of it. The extend function is in lua in one of core files and it doesn't do anything special as far as I can tell.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Prototypes creation

Post by prg »

Hm, yeah, the sanity checking for required attributes and stuff seems to happen either way, so not sure... At least it's shorter and less redundant since you can put a whole bunch of prototype definitions in a single call without needing to repeat the type and name for every single prototype.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Rseding91
Factorio Staff
Factorio Staff
Posts: 15875
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Prototypes creation

Post by Rseding91 »

Both end up doing the same thing so it's really up to how you want to do it.

I personally use the table.deepcopy function when creating modified versions of existing entities since it makes for cleaner code.
If you want to get ahold of me I'm almost always on Discord.
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prototypes creation

Post by orzelek »

Rseding91 wrote:Both end up doing the same thing so it's really up to how you want to do it.

I personally use the table.deepcopy function when creating modified versions of existing entities since it makes for cleaner code.
Oh so there is a built-in function for that - I was using one from Lua wiki.
Official reference doesn't have it and I haven't found info about lua extensions we have here. Only found some of those (like serpent) by finding them in code of other mods.
Post Reply

Return to “Modding help”