Modifying multiple data.raw's in one line

Place to get help with not working mods / modding interface.
Post Reply
HavocsCall
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Jun 23, 2016 10:17 pm
Contact:

Modifying multiple data.raw's in one line

Post by HavocsCall »

I am sorry if this has been posted already, but the search was not helping me

This is purely a personal "OCD" issue and curiousity, but
Is it possible to modify multiple base properties with one line?

I can get this to work

Code: Select all

data.raw["item"]["construction-robot"].flags = {"goes-to-main-inventory"}

data.raw["item"]["construction-robot"].stack_size = 100
But was hoping for something like this:

Code: Select all

data.raw["item"]["construction-robot"].
	flags = {"goes-to-main-inventory"},
	stack_size = 100

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 422
Joined: Tue May 05, 2015 6:07 pm
Contact:

Re: Modifying multiple data.raw's in one line

Post by Afforess »

Not as far as I am aware, but you can cheat and use semicolons:

Code: Select all

local item = data.raw["item"]["construction-robot"]; item.flags = {"goes-to-main-inventory"}; item.stack_size = 100

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Modifying multiple data.raw's in one line

Post by DedlySpyder »

Afforess wrote:Not as far as I am aware, but you can cheat and use semicolons:

Code: Select all

local item = data.raw["item"]["construction-robot"]; item.flags = {"goes-to-main-inventory"}; item.stack_size = 100
Just because you can doesn't mean you should though

HavocsCall
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Jun 23, 2016 10:17 pm
Contact:

Re: Modifying multiple data.raw's in one line

Post by HavocsCall »

DedlySpyder wrote: Just because you can doesn't mean you should though
Why not?

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Modifying multiple data.raw's in one line

Post by DedlySpyder »

HavocsCall wrote:
DedlySpyder wrote: Just because you can doesn't mean you should though
Why not?
One of those things that you're taught not to do in programming; each line should only do one thing.

It just makes the code much easier to understand, if you need to look at it months down the road (or if you stop maintaining it and someone else wants to pick it up) it will be harder to understand.

HavocsCall
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Jun 23, 2016 10:17 pm
Contact:

Re: Modifying multiple data.raw's in one line

Post by HavocsCall »

DedlySpyder wrote:
One of those things that you're taught not to do in programming; each line should only do one thing.

It just makes the code much easier to understand, if you need to look at it months down the road (or if you stop maintaining it and someone else wants to pick it up) it will be harder to understand.
That makes sense. Thanks to both of you

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Modifying multiple data.raw's in one line

Post by bobingabout »

You can do some of this if you use my library mod. for example, you can use bobmods.lib.table_merge (destination, source) to do it, you can write your table directly in as the source table. The problem is that the intended usage was specific, and it might not handle what you're planning to do very well, and might make mistakes.

there are functions in there designs to make the same change to multiple entities at once, such as bobmods.lib.machine.type_if_add_category(data.raw["assembling-machine"], "crafting", "potato-gun") which would add the new crafting category "potato-gun" to every assembling machine that currently has "crafting" set, unless I made mistakes with that command. I use it a few times in my mods.


Probably not very useful for your specific examples though.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”