Page 1 of 1
on_pre_chunk_deleted
Posted: Tue Oct 16, 2018 5:46 am
by Optera
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.
Re: on_pre_chunk_deleted
Posted: Tue Oct 16, 2018 7:10 am
by darkfrei
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
Posted: Tue Oct 16, 2018 7:52 am
by Optera
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.
Why?
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.
Re: on_pre_chunk_deleted
Posted: Tue Oct 16, 2018 8:10 am
by eradicator
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.
+10 for raising events before things vanish into thin air.
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.
Re: on_pre_chunk_deleted
Posted: Tue Oct 16, 2018 9:35 am
by Klonan
Optera 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.
I don't think anybody is suggesting that
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
Posted: Tue Oct 16, 2018 12:39 pm
by Rseding91
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.
Re: on_pre_chunk_deleted
Posted: Fri Oct 19, 2018 3:42 pm
by Optera
Rseding91 wrote: Tue Oct 16, 2018 12:39 pm
The events already exist in 0.17
It already exists?
Is it just not in the 0.17 api preview or does it have a different name?
Re: on_pre_chunk_deleted
Posted: Fri Oct 19, 2018 4:18 pm
by Bilka
Optera wrote: Fri Oct 19, 2018 3:42 pm
Rseding91 wrote: Tue Oct 16, 2018 12:39 pm
The events already exist in 0.17
It already exists?
Is it just not in the 0.17 api preview or does it have a different name?
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.