Mining drill for trees

This is the place to request new mods or give ideas about what could be done.
mg79
Burner Inserter
Burner Inserter
Posts: 18
Joined: Mon Apr 24, 2017 5:32 pm
Contact:

Re: Mining drill for trees

Post by mg79 »

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.
Oop, thanks for the heads up.

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
But it doesn't seem to work, when the on_nth_tick function fires it still complains about not finding the machine key.

Migrations are tricky. :(

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Mining drill for trees

Post by eradicator »

Yea, all find_something things always return coordinate-sorted lists.
mg79 wrote:But it doesn't seem to work, when the on_nth_tick function fires it still complains about not finding the machine key.
Migrations are tricky. :(
If you're doing it in a dev environment the new migration won't fire in an existing save. You need to increase the version number (of any mod? of your mod?) to trigger the migration (and on_configuration_changed) i think. Changes to global table structure are a pain to manage in dev because of the need to trigger them somehow. Also if you're already migrating might as well add global.api_version = 2 or something, so checking is easier next time. /me tries to remember if there's some sort of "last mod version" accessible in migration stage. Current mod version can be found in game.active_mods.

Post Reply

Return to “Ideas and Requests For Mods”