Trouble getting data to persist

Place to get help with not working mods / modding interface.
Post Reply
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Thu May 18, 2017 2:22 pm
Contact:

Trouble getting data to persist

Post by danielbrauer »

Hey, I'm having trouble keeping track of animations I've created across loads. My code looks like this:

Code: Select all

if global.labAnimations == nil then
    global.labAnimations = {}
end
local labAnimations = global.labAnimations

-- table is filled out like this when iterating through all labs:
            if labAnimations[lab.unit_number] == nil then
                labAnimations[lab.unit_number] = rendering.draw_animation({
                ...
This code works fine during a given run, in that only one animation is created per lab. However, when I save and load the game, new animations get created in addition to the ones in the save. I expect the table global.labAnimations to persist, and lab.unit_number to be persistent across save/load. What am I missing?

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Trouble getting data to persist

Post by eduran »

https://lua-api.factorio.com/latest/Data-Lifecycle.html

Check out point 3. The code snippet looks like you are trying to read from and write to the global table during control.lua initialization.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Trouble getting data to persist

Post by danielbrauer »

That was it, thank you! Moving the global references into callbacks fixed the issue, and now my table appears to persist.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users