Storing an Array as a Custom Property
Richard Gaskin
ambassador at fourthworld.com
Fri Oct 1 14:00:06 EDT 2010
Phil Davis wrote:
> On 10/1/10 9:04 AM, Gregory Lypny wrote:
>>
>> Page 236 of the LiveCode user guide says that arrays cannot be
>> stored as single custom properties. Can anyone confirm this
>> please? The reason I ask is that I thought that I had read in
>> a past Rev newsletter that it was now possible, but I may be
>> mistaken.
>>
>> I'm developing an app in LiveCode and have been saving
>> uni-dimensional arrays as single customs props without apparent
>> problems; however, it may be another story with multi-dimensional
>> arrays.
>
> For multi-dimensional arrays you need arrayEncode() and arrayDecode():
>
> put "ice cream" into aMyFoods["favorites"]["desserts"]["cold"]
> set the uMyFoods of stack "dataContainer" to arrayEncode(aMyFoods)
I believe the engine does that automatically when using arrays as custom
prop values.
This would also explain why using deep arrays as prop values is often
much slower than using the natively-addressable two-dimensional arrays
via property sets and properties.
An odd thing about that, though:
Back in August Kevin wrote here:
Can't you do something like this:
put "xyz" into tVar
set the tVar of btn 1 to "a"
You'll end up with a property called xyz that contains "a" in
the default set.
<http://mail.runrev.com/pipermail/use-revolution/2010-August/144541.html>
So by extension, one might think this would work too:
on mouseUp
put "gaskin" into tPropSet
put "richard" into tProp
set the tPropSet[tProp] of me to "Howdy!"
end mouseUp
But it doesn't. It doesn't throw an error, nor set the result to an
error string, but it doesn't set the property either.
Instead the simplest I've found is this:
on mouseUp
put "gaskin" into tPropSet
put "richard" into tProp
set the customPropertySet of me to tPropSet
set the tProp of me to "Howdy!"
end mouseUp
Is there a way to make that a one-liner using array notation?
I know we can do it with hard-wired propset names like this:
set the gaskin["richard"] of me to "Howdy!"
But how can we do it where the propset name is a variable?
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
More information about the use-livecode
mailing list