How do I check that a property exists?

Is there a way to check whether a property exists first, without causing a error that aborts the script?

I’m basically asking if theres a way to check wether go.get() == nil or some sort of go.exists equivilant

	elseif message_id == hash("Damage")  then
		local DamageDealt = unpack(message)
		if go.get(self.MainScript, "CanDodge")  == true then
			msg.post(".", "DodgeTriggered")
			return
		end
		CalculateDamage(self,DamageDealt)

Here’s the code for reference, some entities have the dodge ability, some don’t.

I don’t think there is a clean function to do that, but you can catch errors from go.get with pcall:

if pcall(go.get, self.MainScript, "CanDodge") and go.get(self.MainScript, "CanDodge") then
    msg.post(".", "DodgeTriggered")
    return
end

The best method would be to give all characters a property "CanDodge", and set it to false for those that can’t dodge. Then you can use go.get on all of them.

2 Likes