A little confusion about save stack

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

A little confusion about save stack

Post by magice » Mon Apr 13, 2009 2:25 pm

Where my confusion comes in, is how or if it works in the standalone application. In one of my previous posts about reading and loading an array from a text file, someone had mentioned saving the stack to save the array but I don't understand how that works. What I am hoping to be able to do, is use the save stack command to save a copy of the stand alone app in the state at which it is saved. i.e. the array data that the user has entered is saved and images are as user has left them. is this possible, or does the save stack command only work internally while the app is opened?

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

Post by FourthWorld » Mon Apr 13, 2009 4:04 pm

Saving data in Revolution standalones
by Sarah Reichelt
http://www.revjournal.com/tutorials/sav ... ution.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Mon Apr 13, 2009 9:01 pm

I'm sure that somewhere in that document I can find part of my answer, however I am still a bit confused. Pretty much everything on my app takes place on the mainstack. The only substack is a dialog box. So the "splashscreen" method doesn't seem to be a viable option. The data I need to save is not held in any text areas. instead it exists in a multi dimensional array that may have diferent tags as child elements based on what type of data it holds. Essentially the array is totally unpredictabe in form as well as value. combining an array and writing it to a text file is not a viable option since the array is so unpredictable in form it would be extremely dificult to read it back properly. The only option there that looks at all possible is the "template stack" method. but none of the methods in this document mention the saving of arrays or other variable data so I am not sure how saving a substack helps. What am I missing?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Apr 14, 2009 12:07 am

magice,

you can not save an application to itself. That is the reason why you can't save your application.
BUT you can make your application a little stack that has an Intro and hides itself after a couple seconds. Before that in this little stack you have a script that says "go stack myRealMainStack".
Since the little intro is the application and your realmainstack is just a document that the little intro stack opened, your realmainstack can be saved and you have it next time in the state the user left it.
For this to work you have to include your realmainstack in the settings for the standalone under "stacks" -> add stackfile.
I found this confusing also, but that is the way applications work, they can not save themselves, only documents. Your realmainstack will be build into the standalone, depending on the platform you on you either look (on a mac) into the application bundle (control click on the application icon) and on windows something similar.

I hope this shedded some light on this.

regards
bernd

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Tue Apr 14, 2009 2:30 pm

OK, now that IS helpful. I am still not 100% sure how I will do it, but I know I WILL do it. Thank you very much

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Apr 14, 2009 3:46 pm

magice,

make a small stack and call it MySplash. Put a field into it and that is it.

then make a stack call it "myDocumentStack" also put a field into it.

Then in the mySplash stack in the stack script put

on openstack
send showmyDocStack to me in 5 seconds
end openstack

on showmyDocStack
open stack "myDocumentStack"
hide me
end showmyDocStack

in the script of the stack "myDocumentStack" put

on closeStack
save me
end closeStack

that is it.

Now you build your standalone from mySplash. in the standalone appliation settings under stacks you chose with the button Add Stack file...

your myDocumentStack from its location on disk.

build your standalone

start your application, type something into the text field of mySplash, after 5 seconds myDocumentStack will appear and then type something into the text field .

Quit your application
Reopen it.
the text field in mySplash is empty
the text field in myDocumentStack has the text you put into it. You can add text if you want and so on.

that is the basic idea of a splash-screen stack with a document stack that is savable.

Try this and see how it works. Then you get the idea and do the same for your real stack, voila.

regards
bernd

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Wed Apr 15, 2009 3:30 pm

That is awesome. That was more help then the dozens of documents I have read on the subject. Sometimes I feel like I should be paying a tuition to use these forums.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Wed Apr 15, 2009 9:58 pm

This is working great except for one thing. It saves my fields and image files, but the data that exists in the variables and arrays is disapearing. Is there some other command I need to use to save that data?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed Apr 15, 2009 10:28 pm

It saves everything that a usual save also saves. If you want to have persistence of data that is in variables or arrays you have to put them savable places.
For variable data that is text data (not binary) you can save them into hidden fields, that is the easiest way and you read them out of the field into the variables at start up.
For arrays it is in my opinion the easiest way to store them is in a custom property. (of course you can do that for text data too) then restore everything at start up.
Try this with your simple stack first and see how you can restore the data.
Custom properties are simple to handle once you get the idea behind them.
regards
Bernd

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Apr 16, 2009 12:23 am

This looks promising. I have been able to save single variables to the first cell of a custom property. I have not been able to save a whole array or to access the other cells. is this something I will have to do one element at a time with a repeat loop, or is there a way to set the custom property to a whole array in it's current state.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Thu Apr 16, 2009 1:16 am

Just tried this with a multidimensional array and it seems to work fine.

This takes my array theDataA and puts it into the custom properties. My array is in the format theDataA[1]["field1"] (for use in a datagrid)

Code: Select all

   set the customProperties["myProps"] of this stack to theDataA
After you set the custom property, you should be able to look at the inspector, custom properties, down below where it says custom keys change it to myProps (the name I gave the set when I set the property above) In my case, there are only 4 records at the moment theDataA[1] or [2] etc. Those numbers show up in the inspector when the myProps set is chosen.

To get them back out isn't too bad either.

This will get the information back out of the custom property I created above.

Code: Select all

   put the customProperties[myProps] of this stack into theNewDataA
To check that it works I can do this

Code: Select all

put theNewDataA[1]["Field1"] 
and it will display the data for that set of keys in the message box. In my case that being "Find Payment"

Also wanted to thank you for this thread, I've been learning bucket loads from your questions and everyones responses!
magice wrote:This looks promising. I have been able to save single variables to the first cell of a custom property. I have not been able to save a whole array or to access the other cells. is this something I will have to do one element at a time with a repeat loop, or is there a way to set the custom property to a whole array in it's current state.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Apr 16, 2009 5:15 am

That is exactly what i needed :D

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Apr 16, 2009 2:54 pm

this doesn't seem to be working for me. it worked great with only a single dimensional array, but when I try to save my multi-dimensional array it doesn't create the custom property. This is starting to get quite frustrating.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Thu Apr 16, 2009 3:57 pm

There is actually data in your array when you try to set the property with

Code: Select all

   set the customProperties["myProps"] of this stack to theDataA 
right?

You might try popping a known value out using answer right before that line so you can confirm its got data. The array is declared global too right?

How you declare the global could have an affect on behavior too. Here is an excerpt from the dictionary.

Comments:
You can place the global command either in a handler, or in a script but outside any handler in the script:
* If you declare the global in a handler, the global declaration must appear in each handler in which you use the global. If you declare a global in one handler, and try to use it in another without first declaring it in that handler, the second handler treats it as a local variable, and it does not retain its value between handlers.
Maybe this has something to do with the problem?
magice wrote:this doesn't seem to be working for me. it worked great with only a single dimensional array, but when I try to save my multi-dimensional array it doesn't create the custom property. This is starting to get quite frustrating.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Apr 16, 2009 3:59 pm

magice,
may be you try to access the array directly in the custom property. This works with 1-D arrays, not with multidimensional arrays.
Look what sturgis did.

He puts the whole array into the custom property
set the customProperties["myProps"] of this stack to theDataA
then before accessing the data of the multidimensional array he extracts the array from the custom property
put the customProperties[myProps] of this stack into theNewDataA
(you may want to quote myProps here just in case that you use myProps a a variable name elsewhere in your script.)

And only than he accesses the data in the array
put theNewDataA[1]["Field1"]
This should work if you take the data out of the custom property put it into a variable and access it there.
I guess the problem is somewhere along these lines.
regards
Bernd

Post Reply