In my app, I'm using a lot of tables, not as arrays but as objects with attributes, and there are lots of places where I have to check for an attribute to be set or not. Testing the attribute directly by accessing it throws an error, though, while this is not the case when accessing some other variable that has no value (Nil).
Example:
Code: Select all
Local testVar
testVar = Nil
If testVar ; no problem here
DebugPrint(testVar)
Else
DebugPrint(testVar) ; ouputs "Nil"
EndIf
Local table = {}
table.test = Nil
If table.test ; throws the following error: Table field "test" was not initialized!
DebugPrint(table.test)
Else
DebugPrint(table.test)
EndIf
Of course I can work around this by using an additional
HaveItem():
Code: Select all
If HaveItem(table, "test") And table.test
DebugPrint(table.test)
EndIf
Now, my suggestion is not to throw an error when trying to access a nonexistent table attribute but to return Nil instead, which would make it easier to check an attribute to be present in an If-statement without having to use an additional
HaveItem().