on_pre_chunk_deleted

Post Reply
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

on_pre_chunk_deleted

Post 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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: on_pre_chunk_deleted

Post 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.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: on_pre_chunk_deleted

Post 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.

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

Re: on_pre_chunk_deleted

Post 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.
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.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: on_pre_chunk_deleted

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: on_pre_chunk_deleted

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: on_pre_chunk_deleted

Post 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?

Bilka
Factorio Staff
Factorio Staff
Posts: 3129
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: on_pre_chunk_deleted

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”