A little confusion about save stack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
A little confusion about save stack
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?
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Saving data in Revolution standalones
by Sarah Reichelt
http://www.revjournal.com/tutorials/sav ... ution.html
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
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?
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
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,
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
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
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
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
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.
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)
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.
To check that it works I can do this
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!
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
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
Code: Select all
put theNewDataA[1]["Field1"]
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.
There is actually data in your array when you try to set the property with
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:
Code: Select all
set the customProperties["myProps"] of this stack to theDataA
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:
Maybe this has something to do with the problem?* 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.
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.
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
And only than he accesses the data in the array
I guess the problem is somewhere along these lines.
regards
Bernd
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
then before accessing the data of the multidimensional array he extracts the array from the custom propertyset the customProperties["myProps"] of this stack to theDataA
(you may want to quote myProps here just in case that you use myProps a a variable name elsewhere in your script.)put the customProperties[myProps] of this stack into theNewDataA
And only than he accesses the data in the array
This should work if you take the data out of the custom property put it into a variable and access it there.put theNewDataA[1]["Field1"]
I guess the problem is somewhere along these lines.
regards
Bernd