Custom properties?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Wed Dec 02, 2015 11:22 pm

I was wrong... This does work:

set the pTestX["1"] of this stack to "hi"

so... put max(the pTest["1"] of this stack) should also work. Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Custom properties?

Post by dunbarx » Thu Dec 03, 2015 1:24 am

Greg.

Sure. Anything that can go into a variable can go into a custom property. Like arrays or images.

Craig

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Thu Dec 03, 2015 1:28 am

but.. how would I convert this particular reference to a global?

put item 1 of myline & "," & item 5 of myline & return after SQarray[ALLname]

With SQarray being the global

Because, with properties, you must "set", can't "put after" ?

set the SQarrayProp[ALLname] of this stack to AFTER item 1 of myline ??

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Custom properties?

Post by dunbarx » Thu Dec 03, 2015 3:27 am

Hi.

Just takes a second to get used to the different syntax.

Code: Select all

set the XYZ of this stack to the XYZ of this stack & return & someNewData --appends a new line (after?) to the property
More words than putting data into or after a variable, but nonetheless a simple and straightforward construction.

But remember the original issue. A custom property is a global repository of data, accessible from anywhere within LC, but local to the stack it lives in. If you clone a stack with a custom property from stack "A" to stack"B", that property will be copied over. But then you can modify the contents of each independently.

Globals are common to all stacks in the current session. Change it, and it changes everywhere.

I am saying that the extra words are a non-issue compared with the perfect functionality offered.

Craig

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Custom properties?

Post by Klaus » Thu Dec 03, 2015 1:45 pm

Hi Greg,
adventuresofgreg wrote:...
set the pTestX["1"] of this stack to "hi"
...
this will create a custom property SET named "pTest" with a key named "1" with content "hi" in your stack :D
But using NUMBERS as NAMES (be it for keys or objects) is not a good idea in Livecode!


Best

Klaus

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Thu Dec 03, 2015 2:29 pm

dunbarx wrote:Hi.

Just takes a second to get used to the different syntax.

Code: Select all

set the XYZ of this stack to the XYZ of this stack & return & someNewData --appends a new line (after?) to the property
More words than putting data into or after a variable, but nonetheless a simple and straightforward construction.

But remember the original issue. A custom property is a global repository of data, accessible from anywhere within LC, but local to the stack it lives in. If you clone a stack with a custom property from stack "A" to stack"B", that property will be copied over. But then you can modify the contents of each independently.

Globals are common to all stacks in the current session. Change it, and it changes everywhere.

I am saying that the extra words are a non-issue compared with the perfect functionality offered.

Craig
Thanks a lot Craig. I'll make these changes and run some timed tests and I'll report back. Currently, it seems like there is some kind of cache in the LC engine where it will take some time to load the custom property into the local variable the first time it is called. After that initial load, it runs faster.

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Thu Dec 03, 2015 5:06 pm

ClipArtGuy wrote:

Code: Select all

clone stack "Greg"
set the UniqueDataArray of stack "Greg copy" to DataArray
this should give your copy stack a custom property called "UniqueDataArray" which should contain your array
so clipartguy, just out of curiosity, how are you the "clipartguy" ? :-) PEM me greg@justgreg.com

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Thu Dec 03, 2015 7:02 pm

hmm... still having some problems avoiding dumping that custom property into a variable. Can you think of a way to do this with the property rather than a variable?

Code: Select all

 repeat for each line myline in MetricsArray[Sname]

end repeat
I could dump the pMetricsArray of this stack into a VAR, then split the var into an array, or repeat for each line myline as per example, but then I would have to stick it back into the custom property thereby defeating the purpose of reducing these costly data moves.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Custom properties?

Post by dunbarx » Thu Dec 03, 2015 10:13 pm

An array does not have "lines". Try it. in a button

Code: Select all

on mouseUp
   repeat with y = 1 to 4
      put y into MetricsArray[y]
   end repeat
   breakpoint
   repeat for each line myline in MetricsArray[Sname]
      put sname
   end repeat
end mouseUp
Step through the handler. You can see the array in the debugger, but that is because LC likes you. What do you know, there are no lines in the array at all. If you had

Code: Select all

answer  MetricsArray[Sname]
you would get empty.

Normal LC processes required normal LC variables. You can use arrays all you like, but you cannot manipulate them them with "in the clear" means. You need either array methods, or use the "combine" command to get them into ordinary variable form.

Craig

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Thu Dec 03, 2015 10:45 pm

My arrays have lines

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Custom properties?

Post by dunbarx » Fri Dec 04, 2015 4:10 am

My arrays have lines
Well, not really, and in any case they are not accessible in the clear. Did you try my handler above? Arrays are associations of keys and elements. They have no "ordinary" structure, like lines delimited by returns.

Craig

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Fri Dec 04, 2015 2:28 pm

Arrays with lines:

Code: Select all

Repeat for each key mykey in MyArray
 Repeat for each line myline in MyArray[MyKey]
    Repeat for each item myitem in myline

End repeat
  End repeat
End repeat


Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Custom properties?

Post by Klaus » Fri Dec 04, 2015 2:33 pm

Hey, the CONTENT of array keys does not count! :D

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: Custom properties?

Post by adventuresofgreg » Fri Dec 04, 2015 2:37 pm

image.jpg
I'm concerned with speed. When the user moves the sliders, the graphs and metrics are updated in real time. So, there is a lot of sorting through many very large arrays that are retrieved from a SQL DB. I wrote my own graphing functions also (no ChartsEngine).

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Custom properties?

Post by dunbarx » Fri Dec 04, 2015 3:45 pm

Your app looks very professional.

So without getting into a discussion that likely is just about terminology and semantics, your code snippet deconstructs the array via its keys, as Klaus alluded to. The "combine" command deconstructs an array as well, bringing it into the clear, as I like to say.

I only care that you understand that if you make an array, and then do something like:

Code: Select all

answer yourArray
That you do not think anything is amiss when you get empty as a result.

Craig

Post Reply