Data Persistence

Ben Rubinstein benr_mc at
Tue Jul 31 14:01:38 EDT 2018

Hi John, welcome to the gang.

FWIW, if your needs are super-simple, saving the values of various fields - 
and especially if those fields are not going to have multi-line values, you 
may want to check out the keywords 'combine' and 'split'.

Combine takes a (simple, not nested) array and combines it into flat text with 
the delimiters you specify for keys and records; split does the reverse.

So what I've done for this kind of case - simple mobile app, storing some 
simple values in case it gets backgrounded - is keep all the data in an array; 
update the array when the data changes (e.g. user edits a field, or some other 
event) - and then calling a command along these lines:

	command storeSettings
	   global gaSettings
	   local tPath, tFlat
	   put gaSettings into tFlat
	   combine tFlat using return and tab
	   put format("file://%s/settings.txt", prefsFolder()) into tPath
	   put tFlat into URL tPath
	end storeSettings

The advantage over arrayEncode is that the file is very readable - with the 
above delimiters, each line is an entry from the array, in the format 
<key><tab><value>.  I know Richard questions why one would ever want to read 
"LSON": my answer is that during development it can be helpful, either 
directly when developing on desktop, or attaching to error reports once the 
app has moved onto a device.

The disadvantage is that you need a couple of characters that you know won't 
be included in either key or value. It doesn't have to be tab and return; you 
could use "◊" and "¶" - but if you have any doubts of what your users might 
ever need to enter, this is an issue.



On 27/07/2018 19:37, John McKenzie via use-livecode wrote:
>   Thanks for the extra comments everyone. Glad my thought process was
> correct, databse is overkill, saving every text change is too much,
> etc, etc.
>   As I said I will not be able to really do anything until next week.
>   Thanks for mentioning the closeField command guys. I will check it
> out, but the name sounds like it explains it, loose focus on the field,
> field is closed, handling activated.
>   Because I like word play I might make my own text file format, the
> "Extended Livecode Optimized Serialized Object Notation" format or
> ELSON. It adds just enough features to LSON to make identical to JSON.
> Being stupid and redundant it will be the hot new buzzword in the
> computing industry.
>   Using arrays intigues me, especially if I can just keep it in RAM (It
> is a small amount of data for sure).
>   Thanks for your continued help everyone. Off to super busy weekend
> planning and working on an event for Sunday. Will update you/ask
> follow-ups next week.

More information about the use-livecode mailing list