entry.entity and entry.entity.valid ?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

entry.entity and entry.entity.valid ?

Post by ownlyme »

i know that in events, you should use both.
But is there any case where you need both safety checks for a reference you stored in a variable?
For example when the entity/gui/etc gets removed upon mod uninstallation?

when i destroy an entity, its reference usually (always?) remains in the variable, it'll just be invalid
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

slippycheeze
Filter Inserter
Filter Inserter
Posts: 587
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: entry.entity and entry.entity.valid ?

Post by slippycheeze »

If you are holding the entity with as strong reference, in a private table or variable, then it will not become nil magically, no.

The whole valid thing exists literally because of that fact, so yeah, you can omit the nil check if you want. The extra nil check is, like, absolutely free, but if you feel strongly, skip it.

Post Reply

Return to “Modding help”