on_pre_chunk_deleted
on_pre_chunk_deleted
Having on_pre_chunk_deleted alongside on_pre_surface_cleared and on_pre_surface_deleted would allow to finally move away from checking isValid every tick just to prevent other mods literally pulling the rug from under your scripted entities.
My Mods: mods.factorio.com
Re: on_pre_chunk_deleted
But this check is must be there. I mean, just one check can save whole script, if not valid, then delete this handler with this not valid entity from the table.
Re: on_pre_chunk_deleted
Why?darkfrei wrote: Tue Oct 16, 2018 7:10 am But this check is must be there. I mean, just one check can save whole script, if not valid, then delete this handler with this not valid entity from the table.
With the way that's preached here every mod checks each of it's scripted entities every tick. All this overhead is avoidable through events.
Ideally an event fires whenever entities may become invalid allowing entity validation entirely through event handlers.
Going one step further surface and chunk removal should implicitly call on_entity_removed for each entity removed. But with on_pre_chunk_deleted I can work around this in my mods entirely.
Yes these will make deleting chunks and surfaces more expensive, but compare how often that happens to on_tick.
My Mods: mods.factorio.com
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: on_pre_chunk_deleted
+10 for raising events before things vanish into thin air.Optera wrote: Tue Oct 16, 2018 7:52 am Ideally an event fires whenever entities may become invalid allowing entity validation entirely through event handlers.
Having to compensate for each case where some other mod might have messed with my entities is not only a cost on UPS but also a headache to manage, a source of bugs and requires more code than if i didn't have to guess if something happend or not.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: on_pre_chunk_deleted
I don't think anybody is suggesting thatOptera wrote: Tue Oct 16, 2018 7:52 am With the way that's preached here every mod checks each of it's scripted entities every tick. All this overhead is avoidable through events.
You should always check an entity is valid before using it, and it is one of the cheapest calls you can make on an entity, but there is no requirement to go out of your way to check them all each tick
Re: on_pre_chunk_deleted
The events already exist in 0.17 however it isn't going to address your reason.
You will always need to check if an entity is valid before you use it because their are multiple ways it can become invalid outside of events. It's simply not possible to always have an event when an entity is removed/invalidated and as such you need to a always check them before you use them.
You will always need to check if an entity is valid before you use it because their are multiple ways it can become invalid outside of events. It's simply not possible to always have an event when an entity is removed/invalidated and as such you need to a always check them before you use them.
If you want to get ahold of me I'm almost always on Discord.
Re: on_pre_chunk_deleted
It already exists?
Is it just not in the 0.17 api preview or does it have a different name?
My Mods: mods.factorio.com
Re: on_pre_chunk_deleted
It didn't exist at the time he made that comment, I added it on Wednesday. The api preview was updated on Monday afaik, so it doesn't show it yet.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.