There is a really annoying issue for me: everytime i try to save something about entities and then the entity gets destroyed every table and variable referring to that entity gets reset, even globals.
E.g. having a for loop around a table of entities and one of the entities gets destroyed, the table gets the value of that entity removed and the for loop starts completely from the beginning regardless of where it was, running the body on some of the entities twice. I will use chests as an example. Something as simple as that:
Code: Select all
script.on_init(function()
local chests = game.surfaces[1].find_entities_filtered{name = {"logistic-chest-requester", "logistic-chest-passive-provider"}}
local i=0
for k, v in pairs(chests) do
if v.name == "logistic-chest-passive-provider"
i = i+1
end
if v.name == "logistic-chest-requester"
v.destroy()
end
end
game.surfaces[1].print(i)
end)
Or having a local save a chests inventory (on init! the local isn't touched, only read i promise!) to insert its stacks into another inventory later. Once the chest gets destroyed, doesn't matter wether by being damaged, mined or via a script, the local gets reset making saves impossible. For globals (variables and the table) its the same.
Code: Select all
local chest = game.surfaces[1].find_entity("logistic-chest-requester", pos1)
local newchest = game.surfaces[1].find_entity("logistic-chest-requester", pos2)
local invtry = chest.get_inventory(1)
chest.destroy()
for u=1, #invtry do
if invtry[u].valid_for_read == true then
newchest.insert({name = invtry[u].name, count = invtry[u].count})
end
end
How else am i supposed to lets say replace a requester chest with a buffer chest if i can't save the request slots in the script? Do i really have to create a "bridge-entity" e.g. a requester chest on a different surface just to temporarily save the properties i want to have? I hope that this is not supposed to be the case because it's really annoying. I've done a lot of testing on that because i couldn't believe it at first and thought i was simply a bad programmer and i'm still not convinced, but as much testing as i did i doubt that as well. So contradictory.
Now i have so many questions. Can you confirm that? Can you repeoduce? If not, can one of your friends? Is it supposed to be this way? Is there an error in my game files? Or am i just not good enough to write working scripts? If there is really a bug, is the reason for all these errors really that the variables get reset? Or did i misinterpret and there's another bug going on? Was it correct to post it in discussions since i don't need help with a specific mod? Or should i have posted it in help since i couldn't solve this myself?
And everybody who read this wall of thext thanks for your patience.