How to work with custom properties that are nested arrays
If you try to create a custom property (e.g. of the stack) that is a nested array, then you might run into problems when querying the values of some nested elements. For example, suppose the stack has the following custom property, that is a nested array:
cAnimals
… cats
… … sylvester = whiskers
… … tom = meow mix
… dogs
… … scooby = scooby snacks
… … rufus = chum
Let's try querying various values, using the message box:
put the customKeys of this stack
returns cAnimals, as expected
put number of elements of the cAnimals of this stack
returns 2 (correct - cAnimals contains "cats" and "dogs")
put number of elements of the cAnimals["cats"] of this stack
returns 0 (but this should return 2 shouldn't it? Because cAnimals["cats"] contains "sylvester" and "tom")
put the cAnimals["cats"]["sylvester"] of this stack
Returns "Script compile error: Error description: Expression: bad factor"
One can notice that trying to reference anything other than the top-level custom property "the cAnimals of this stack" results into errors. However, this is expected, since the custom property is just the cAnimals. So how can we get the value of a nested element?
Solution:
In this case, we have to use a temp variable that will hold the (nested) array, and then query the temp variable, as we would do with any array variable:
local tArr
put the cAnimals of this stack into tArr
put the number of elements of tArr["cats"]
local tArr
put the cAnimals of this stack into tArr
put tArr["cats"]["sylvester"]
0 Comments
Add your comment