entry.entity and entry.entity.valid ?

Place to get help with not working mods / modding interface.
User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 445
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
creator of 55 mods
My api requests/suggestions: ui relative for overlay||Grenade arc||Player Modifiers||textbox::selection||Singleplayer RCON||disable car's ground sounds
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”