Page 1 of 1

Storing large amounts of data in a script only stack

Posted: Wed Feb 08, 2017 11:58 pm
by Simon Knight
Hi,
I have decided to try script only stacks and have hit a problem when converting a small library stack dealing with coordinate conversion. The stack in question refers to a block of data stored in a custom property of the original stack file, the data converts the Ordnance Survey OSGB 1936 grid squares between their text and numeric values (good luck attempting to compute the conversion) :
  • HP 4 12 400000 1200000
    HT 3 11 300000 1100000
    HU 4 11 400000 1100000
    HW 1 10 100000 1000000
    HX 2 10 200000 1000000
    HY 3 10 300000 1000000
    HZ 4 10 400000 1000000
    NA 0 9 0 900000
    NB 1 9 100000 900000
    NC 2 9 200000 900000
    ND 3 9 300000 900000
    NF 0 8 0 800000
    NG 1 8 100000 800000
    NH 2 8 200000 800000
    NJ 3 8 300000 800000
    NK 4 8 400000 800000
    NL 0 7 0 700000
    NM 1 7 100000 700000
    NN 2 7 200000 700000
    NO 3 7 300000 700000
    NR 1 6 100000 600000
    NS 2 6 200000 600000
    NT 3 6 300000 600000
    NU 4 6 400000 600000
    NW 1 5 100000 500000
    NX 2 5 200000 500000
    NY 3 5 300000 500000
    NZ 4 5 400000 500000
    OV 5 5 500000 500000
    SC 2 4 200000 400000
    SD 3 4 300000 400000
    SE 4 4 400000 400000
    SH 2 3 200000 300000
    SJ 3 3 300000 300000
    SK 4 3 400000 300000
    SM 1 2 100000 200000
    SN 2 2 200000 200000
    SO 3 2 300000 200000
    SP 4 2 400000 200000
    SR 1 1 100000 100000
    SS 2 1 200000 100000
    ST 3 1 300000 100000
    SU 4 1 400000 100000
    SV 0 0 0 0
    SW 1 0 100000 0
    SX 2 0 200000 0
    SY 3 0 300000 0
    SZ 4 0 400000 0
    TA 5 4 500000 400000
    TF 5 3 500000 300000
    TG 6 3 600000 300000
    TL 5 2 500000 200000
    TM 6 2 600000 200000
    TQ 5 1 500000 100000
    TR 6 1 600000 100000
    TV 5 0 500000 0

I propose to use a text editor to replace the tabs with commas and add the line continuation character to each line and then copy it back into LC and wrap it in quotes and save to a variable. Once it is in a variable I can use it as necessary. But I wonder if there is a better way.

Any ideas?

Thanks

Simon

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 12:50 am
by FourthWorld
A script-only stack will only save the stack script - no properties.

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 2:30 am
by dunbarx
What made you, beyond just for experimentation, want to go outside of the original stack?

I try to keep everything as local as possible. Is the size you mentioned looming large?

Craig Newman

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 8:38 am
by Simon Knight
Its all just an experiment: I have just watched Trevor Devore's video which demonstrates editing scripts using the text editor Sublimetext3. This offers some powerful features which are not available in the IDE and also reminds me of the tRev editor which I use to use. Also I am attracted to being able to place script only stacks under some form of version control such as Git.

The video also mentions that the simplest stacks to convert to script only are library stacks as these have no user interface. So I chose a small library stack, I created long ago, for conversion by way of an experiment. While my source stack has no important UI components it does use a custom property as method of storing a longish list of data as listed in my original post. Richard has confirmed that script only stacks are just text and they do not allow custom properties to be used. Even if they did there would still be the question of how to populate them.

It seems that my only option is to enter the data into a variable as a long string in quotes. This can be as part of a new initialisation routine. However, thinking back I remember that some versions of the BASIC language allowed information to be pasted into the code following a token of DATA: so I wondered given Livecode's history if any similar command exits or if there are any other options.

Craig asks why I am trying this? Good question! I want to identify the advantages, disadvantages and difficulties of using ScriptOnlyStacks. Disadvantage (1): working with large amounts of constant data is more complicated than just dumping it into a custom property.

Another couple of disadvantages are that I have been unable to find much documentation about script only stacks. Also this forum rejects the words "script only stack" in searches for being to common (frequent not base!). So once this is posted I am going to search for "ScriptOnlyStack" to see if that is allowed.

Two more questions : do you ever use external text/code editors and how do you manage version control of your projects ?

best wishes

Simon K

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 10:17 am
by rkriesel
Simon Knight wrote:... But I wonder if there is a better way ...
Hi, Simon. Here's an example of a technique that builds an array from data embedded in a script-only stack:

Code: Select all

local sArray

on preOpenStack
    loadArray 5 -- for five lines of data
end preOpenStack

command loadArray p
    get line -p - 1 to -2 of the script of me
    split it by cr and comma
    put it into sArray
end loadArray

on openStack
    breakpoint -- investigate sArray
end openStack

/* lines below are input to handler loadArray:
a,apple
b,banana
c,coconut
d,dachshund
e,elephant
*/
For a large or complex array, you can embed in your script an encodedArray, and decode it to load the array.
Or you can embed xml, or json, or whatever, and decode that (as long as the embedded data doesn't affect compiling your script).
For multiple arrays, you can use multiple ranges of script line numbers.

Does this idea work for you?

-- Dick

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 1:57 pm
by Simon Knight
Dick,

Thats brilliant!

Yes, it does work for me!

Thanks for your elegant solution.

best wishes

Simon

Re: Storing large amounts of data in a script only stack

Posted: Thu Feb 09, 2017 5:15 pm
by FourthWorld
I'm curious: since the data is already in a file, why does it need to be embedded in the app? Why not just include the file along with the app where it can be read in when needed? As a separate file it not only keeps the stack focused on code, but would also allow the data to be updated without having to replace the app.