Richard,
Thx, this was a helpful hint! Didn't know about this PDF, after all these years ...
I'll try to explain the customProperty/ array confusion:
(this is as I understand it, anybody feel free to correct me!)
User Guide wrote:All the custom properties in a custom property set form an array. The array's name is the
custom property set name, and the elements of the array are the individual custom
properties in that custom property set.
For me this translates to:
If you're using array notation addressing a customProperty,
LC only thinks of the customProperties and customPropertySets,
and NOT of the contents of an array stored in any of these!
So:
refers to the customProperty "myProp" of the customPropertySet "cProp" of the current stack!
And:
Code: Select all
put "one" into myArray[1]
put "two" into myArray[2]
set the cProp of this stack to myArray
answer the cProp[1] of this stack
returns empty - there is no customPropertySet "cProp" with a customProperty "1" :/
But there's a way:
User Guide wrote:If you store a set of custom properties in a custom property set, the set can be used just
like an array. You can think of the custom property set as though it were a single custom
property, and the properties in the set as the individual elements of the array.
So we have to:
Code: Select all
put "one" into myArray[1]
put "two" into myArray[2]
set the customProperties["myProp"] of this stack to myArray
answer the myProp[1] of this stack
We created a customPropertySet "myProp" with 2 customProperties ("1" & "2"), and the answer is "one". Bingo!
Unfortunately, we'll hit the wall if we try to use nested arrays:
Code: Select all
put "one" into myArray[1]["vEng"]
put "uno" into myArray[1]["vIta"]
put "two" into myArray[2]["vEng"]
put "due" into myArray[2]["vIta"]
set the customProperties["myProp"] of this stack to myArray
answer the myProp[1]["vIta"] of this stack -- <= This doesn't work!
The last line doesn't compute :/
Additionally, we cannot retrieve the whole former myArray once we stored it:
Code: Select all
put the myProp of this stack into myNewArray
This results in an empty variable :/ (after all, it's a whole customPropertySet!)
We only can grab the entries one at a time:
Code: Select all
put the myProp[1] of this stack into myNewArray
answer myNewArray["vIta"]
Conclusion:
If we need to work with arrays that are more than simple key/value pairs, then the best choice is just to throw the whole thing into a simple customProperty:
Code: Select all
put "one" into myArray[1]["vEng"]
put "uno" into myArray[1]["vIta"]
put "two" into myArray[2]["vEng"]
put "due" into myArray[2]["vIta"]
...
set the cMyPhatArray of this stack to myArray
From there, we can easily read, sort & modify it, and write it back afterwards:
Code: Select all
put the cMyPhatArray of this stack into myArray
answer myArray[2]["vIta"]
put "three" into myArray[3]["vEng"]
put "tre" into myArray[3]["vIta"]
set the cMyPhatArray of this stack to myArray
So copy the cProp to a variable, play with it, write it back.
Have fun!