Oop, thanks for the heads up.eradicator wrote: Also there's a built-in module called "util" so you might want to use a different name in the future to avoid confusion.
Hm..also removed the "harvest closest trees first". The only beauty function i added to the original, because i thought it looked/felt really meh if it starts in some far away corner. Especially if the player is trying to see if it works and doesn't see the far-away trees vanishing.
I might put a similar function back in, it was quite neat, but I took it out for the initial version as I tried to keep it simple. Seems like the find_entities_filtered will search from top left to bottom right, which does look pretty bad.
......
Ok I tried to do it the way you showed. Which works if I start a new game. But in an existing save it now complains about not finding the key in the array, which makes sense. So I tried adding a migration function:
Code: Select all
if (global.woodHarvesters) and (global.woodHarvesters[1].machine == nil) then
tempHarvesters = {}
for i,harvester in pairs(global.woodHarvesters) do
tempHarvesters[i] = {["machine"]=harvester,["range"]=2}
end
global.woodHarvesters = tempHarvesters
end
Migrations are tricky.
