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 » Fri Dec 04, 2015 9:58 pm

This interesting Craig. Let me ask then, what would be the most efficient way of storing and retrieving data in an array.

Raw data:

a return delimited list, each mine containing tab delimited items, with the last item being a very large comma delimited group of 'sub' items. And this list might be 10's of thousands of lines long.

And, there are a few dozen of these lists.

So what I do, is store each list in its own array: masterfata[symbol]

Then when retrieving it, I repeat for each line, repeat for each item and thrn perform some function on that last item of hundreds of comma delimited items.

I could treat each line as a sub array, but calling the repeat for myline/myitem seems just as fast from tests.

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 » Sat Dec 05, 2015 12:09 am

Hmmm.

I guess we are just not communicating well, since you are obviously running this just fine. To make sure, run this in a button:

Code: Select all

on mouseUp
   repeat with y = 1 to 10
      put y * 10 into myArray[y]
   end repeat

   answer "Line 5 of the array is:" && line 5 of myArray -- empty
   answer "Key 5 of the array contains:" && myArray[5] --50
end mouseUp
You get empty for the line, because you cannot access a "line" in an array by ordinary means. So when you say that
Then when retrieving it, I repeat for each line...
you must mean that you are somehow transforming the array data into clear data. With the "combine" command, perhaps? Because you cannot use the sort of gadgetry I used in the first "answer" part of the above code directly on an array.

Craig

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

Re: Custom properties?

Post by adventuresofgreg » Sat Dec 05, 2015 12:16 am

But you didn't put a return key char into your array. Therefore there would be no lines.

Put x*10 & return after myarray[x]

Then you can

Put line 10 of myarray[x]

??

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 » Sat Dec 05, 2015 12:36 am

Greg.

If I run this:

Code: Select all

on mouseUp
   repeat with y = 1 to 10
      put y * 10 & return after myArray[y]
   end repeat
   
   answer "Line 5 of the array is:" && line 5 of myArray -- empty
   answer "Key 5 of the array contains:" && myArray[5] --50
end mouseUp
I get empty in the first "answer". If I step through, I see the same array exploded in the variable watcher. The return does nothing, though I was excited that I might discover something entirely new (for me) about arrays

BUT:

Code: Select all

on mouseUp
   repeat with y = 1 to 10
      put y * 10 & return & return after myArray[y]
   end repeat
   
   answer "Line 5 of the array is:" && line 5 of myArray -- empty
   answer "Key 5 of the array contains:" && myArray[5] --50
   answer the number of lines of myArray[5]
end mouseUp
Hmmm.

Craig

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

Re: Custom properties?

Post by adventuresofgreg » Sat Dec 05, 2015 12:43 am

Craig. I'm travelling at the moment and can't go through your code. But you can put any character into an element of an array. Return, tab, comma. An entire book if you want. And then refer to line x of mybook[thisbook]

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 » Sat Dec 05, 2015 3:58 am

Greg.

I know. If you add two returns to an element of an array, and then extract it, you will get two lines.

That was a teaser.I was (am) still trying to figure out how your arrays have lines. But rereading your last post, you imply that you have indeed extracted the elements of your array. That was all I ever asked, whether you used, say the "combine" command to put your array data "in the clear". You never said...

Craig

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

Re: Custom properties?

Post by Klaus » Sat Dec 05, 2015 1:09 pm

As I wrote a couple of days before, Greg has lines in the CONTENT of his array keys and that does not count!
But obviously noone was listening, the story of my life... :D

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 » Sat Dec 05, 2015 4:01 pm

Klaus.

I am the one who writes things, and then they are passed over, being re-suggested downPost by others. Not you. It is the nature of modern quick reading. Many join a thread at the end, unless they have been involved all the way through, and start at that point.

I saw your post when it came through. You and I are on the same page.

Anyway,I think this thread has reached a dead end. Greg knows what he is doing; I just wanted to clarify the ideas. Many posts concern just what I am on about, that an array cannot be "seen" without it being changed into "ordinary" form.

Craig :wink:

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

Re: Custom properties?

Post by adventuresofgreg » Sat Dec 05, 2015 4:29 pm

I think I was getting confused over terms. But my original problem was resolved with your solution Craig - to use a custom property and I thank you for that.

The drawback to using a custom property over a global variable, is that you can't "process" the data in the custom property without extracting it first. And this extraction (or, combine, or decompose if it's an array) takes time. Whereas, you can manipulate and process data within an array in a global without ever having to decompose it.

When using the globals, my script was processing the data in about 60 to 100 ms which is fast enough to allow the user to change settings by sliding a scroll bar and watch the analysis in near real time. When loading the globals into and out of the custom property, that additional step was ADDING 1000 to 2000 ms which is too slow.

I did find a fix to this problem. I changed the global arrays to local, then check to see if the local array is empty in which case, I load it from a custom property. Since this only needs to be done once, the 2000 ms time required to haul the data from the property into a local is acceptable.

This move from globals to locals with a custom property load, now allows me to create multiple clones of the stack, and I can choose what data to share among all open stacks, and which data to keep as local to the stacks.

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 » Sun Dec 06, 2015 6:29 am

Greg.

Right on.

Craig

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Custom properties?

Post by sritcp » Sun Dec 06, 2015 3:05 pm

I have a question about custom properties and would appreciate some light.

Custom properties survive across sessions while global variables would have to be written out to a file to be saved, right?
How would this work in the context of an app, which would need to be updated?
Wouldn't the current state of a custom property be lost when a new stack file replaces the old?
To prevent this, the custom property would have to be written out to a file every time (just like a global), wouldn't it?

Thanks,
Sri

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Custom properties?

Post by sritcp » Sun Dec 06, 2015 3:13 pm

By the way,

Interesting website, Greg!

Sri

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Custom properties?

Post by jmburnod » Sun Dec 06, 2015 6:31 pm

Sri
To prevent this, the custom property would have to be written out to a file every time (just like a global), wouldn't it?
Yes. Globals and customproperties should be written out to a file and imported at preopenstack or what you want.
How would this work in the context of an app, which would need to be updated?
When you update your app you change standalone only and it Import file
from the disk to globals or custom properties
Best regards
Jean-Marc
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Custom properties?

Post by FourthWorld » Sun Dec 06, 2015 7:09 pm

adventuresofgreg wrote:...what would be the most efficient way of storing and retrieving data in an array.
Arrays can be made into persistent forms in two ways: serialized with arrayEncode, or stored in a stack file.

ArrayEncode/arrayDecode is reasonably efficient (much more so than storing in intermediary formats like JSON or XML), but when the array size is mall enough (in my tests, < 100 MB or so) you may find creating stack files for storing arrays represented within them as customproperty sets and custom properties to be the fastest method of loading array data from a cold boot.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Custom properties?

Post by sritcp » Sun Dec 06, 2015 10:24 pm

jmburnod wrote:.....customproperties should be written out to a file ........
Thanks Jean-Marc!

Sri

Post Reply