Page 1 of 1

Modifying multiple data.raw's in one line

Posted: Thu Jun 23, 2016 10:24 pm
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

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

Posted: Fri Jun 24, 2016 2:31 pm
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

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

Posted: Fri Jun 24, 2016 4:23 pm
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

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

Posted: Fri Jun 24, 2016 6:43 pm
by HavocsCall
DedlySpyder wrote: Just because you can doesn't mean you should though
Why not?

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

Posted: Fri Jun 24, 2016 6:46 pm
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.

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

Posted: Fri Jun 24, 2016 6:51 pm
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

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

Posted: Mon Jun 27, 2016 8:34 am
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.