Spreading a table out over several ticks

Place to get help with not working mods / modding interface.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Spreading a table out over several ticks

Post by FuryoftheStars »

Ok, so I've noticed that using the deepcopy hurts the ups greatly over ~4k planters (at ~8k, ups was ~30), so I've changed it to simply local planters = global.planters (and local saplings = global.saplings, respectively) and that fixed it. However, if someone could clarify something for me... I may be getting this confused with another language or even a different data type, but with tables, if I simply do a table2 = table1, am I actually making a copy of that table, or merely creating a reference to it? I'm worried that it's a reference and so if anything happens to trigger the add while it's looping, it'll still error.


------------------------------------------

Qon wrote:
Thu May 05, 2022 5:07 pm
FuryoftheStars wrote:
Thu May 05, 2022 3:04 pm
FuryoftheStars wrote:
Thu May 05, 2022 12:25 pm
I noticed that at ~2k planters with ~1.5k saplings growing I was taking a 5-10 ups hit.
Whoops. Meant ~4k planters and ~3k-3.5k saplings.
Use the edit button.
That was 3 hours later. If it'd only been a few minutes, I would've.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Spreading a table out over several ticks

Post by Klonan »

FuryoftheStars wrote:
Thu May 05, 2022 6:14 pm
with tables, if I simply do a table2 = table1, am I actually making a copy of that table, or merely creating a reference to it?
You're creating a reference to it, with strings and numbers would it make a copy

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Spreading a table out over several ticks

Post by FuryoftheStars »

Klonan wrote:
Thu May 05, 2022 7:32 pm
FuryoftheStars wrote:
Thu May 05, 2022 6:14 pm
with tables, if I simply do a table2 = table1, am I actually making a copy of that table, or merely creating a reference to it?
You're creating a reference to it, with strings and numbers would it make a copy
Thanks, Klonan!


Hmm, ok. Maybe I'd be better off using this other method, then:
FuryoftheStars wrote:
Thu May 05, 2022 3:49 am
setting of a variable to true when the add event is called, and checking that var's state on each iteration of the loop, breaking if true (and then setting back to false for the next tick).
I realize the chances of the error occurring are remote (probably even theoretically not supposed to happen), but as I was able to trigger it once, I don't want to have to field bug reports on it later. :P
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Modding help”