What does this property mean? I've been trying to fix up a mod (Filtered splitters by ThaPear) for 0.12.1 to check how it works but for some reason if it check whether a entityis valid it returns false.Reworked all LuaObjects that can be invalid to support the "valid" readable property.
When is a factorio-object "invalid"?
When is a factorio-object "invalid"?
In 11.14 there was the following addition to lua-objects in factorio:
Re: When is a factorio-object "invalid"?
I think a object if valid if it still exists.
So in a few mods i made, i would add them to a global index when they are created. If they were then deconstructed, the global entry would become invalid for that entity.
If i didn't check if the entity was valid, then i would get an nil reference error
So in a few mods i made, i would add them to a global index when they are created. If they were then deconstructed, the global entry would become invalid for that entity.
If i didn't check if the entity was valid, then i would get an nil reference error
Re: When is a factorio-object "invalid"?
So pretty straight forward, I think I just made a mistake then. Thank you.
-
- Fast Inserter
- Posts: 157
- Joined: Fri Jun 26, 2015 11:13 pm
Re: When is a factorio-object "invalid"?
Think of invalid objects as dangling pointer references. There are quite a few way an object can be removed from the game (and not all of it will be under your control, so it might not be your fault*.) so the ".valid" attribute allows you to do some defensive programming. Obviously, it's best if you don't have to deal with it, but sometimes the cost of checking ".valid" may be less than handling on_destroyed() for everything in the game.Xyfi wrote:So pretty straight forward, I think I just made a mistake then. Thank you.
* For example, if I write a "bomb" mod that destroys everything in a given radius, including your object, you might not know that your object is removed from the game until you check its valid status.