Checking if an instance is nil

Hey there, new to defold and lua, trying to get used to it over Unity.

In my scene, I have a level.collection used in the main that contains the player game object. When his health is under 0, I delete him. This is all fine and good, but it them messes with my bad guy AI due to them no longer being able to reference his location to decide where they shoot. I’ve tried looking for ways to check that the player ~= nil, so they don’t do the related behavior in those cases, but I could not find any direct response on how that might work in defold.

So my question is, does lua/defold have a way to see that and Instance does not exist without causing an error, and if so, how would one check that?

It looks like there is no direct way to do this, see: Checking if a url exists Usually I try to organize things so those url references all get set to nil when the object is deleted. (in which case this thread might be relevant: Send a message to all objects?)

2 Likes

I’ll look into it, thank you very much!

1 Like