How to check if a custom property is set?

Started by artium, Sat 15/09/2018 12:28:40

Previous topic - Next topic

artium

I searched a bit, but could not find an answer for this.

Suppose I have a custom property "X" that some hotspots have and others does not.

I iterate over every hotspot and do "h.GetProperty("X");" the game will crash because some do not have this property set.

Is it possible to provide default value for properties or to test if a hotspot have this property set before accessing it?

Snarky

If you create a custom property for Hotspots, all hotspots have that custom property. When you create it, you can also set a default value that will be used for those hotspots where you don't set it directly.

artium

But what if I am developing a module that use this property and don't want to rely on module's user setting it.
How can I protect my module from crashing the game?

Crimson Wizard

User must set that property anyway, this is how it currently works in AGS: property only exists if it's set by user at design-time, and if they did it will be available for each object of corresponding type.
So, you cannot really do anything about that, because there is no script command that would create a new property, only one that sets new value to existing one.

Only practical approach here is to make a note in the module's description that game author should add certain properties in order to be using your module.

Snarky

But also, if you do a GetProperty() call for a non-existent property name, I don't think it will crash, just return a 0 or null (for text properties).

Crimson Wizard

Quote from: Snarky on Sat 15/09/2018 15:43:32
But also, if you do a GetProperty() call for a non-existent property name, I don't think it will crash, just return a 0 or null (for text properties).

It will display error "there is no such property", and I actually think that's not a bad thing in current situation, since there is no other way to tell if it exists. At least user will be warned early instead of wondering why script does not work correctly.

SMF spam blocked by CleanTalk