Any help would be appreciated
Stack custom properties
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Stack custom properties
Hey all. I'm making an app that I want to use stack custom properties to save preferences between sessions. Unfortunately, I'm not having much luck with it
. I'm using the Dropbox stack, which is working fine, but I want to then save the Dropbox key and secret key for future sessions. The issue is I can't figure out how to save a stack's custom properties
. I read that I can't save it in the same stack of my standalone, but I'm not sure how to get it to save to a different stack. Do I need an if statement to check if a stack exists, and if so, open that stack to get the properties, and if not, create that stack to be used?
Any help would be appreciated
Any help would be appreciated
Re: Stack custom properties
Hi.
You cannot save anything at all in the executable. No OS will permit it.
I always use the "splash" stack method. You make a simple stack that may do nothing at all but open itself. In its standalone settings, you will add one or more entirely different stack files (not substacks) to that base stack file. All those others can save anything you can throw at them.
Craig Newman
You cannot save anything at all in the executable. No OS will permit it.
I always use the "splash" stack method. You make a simple stack that may do nothing at all but open itself. In its standalone settings, you will add one or more entirely different stack files (not substacks) to that base stack file. All those others can save anything you can throw at them.
Craig Newman
-
quailcreek
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Stack custom properties
Hi Opaquer,
Are you writing your app for Mac, Win, Mobile? There are several ways of saving preference data. A separate stack, a text file, etc. Depends on the platform.
Take a look here:
http://forums.livecode.com/viewtopic.php?f=9&t=10728
Are you writing your app for Mac, Win, Mobile? There are several ways of saving preference data. A separate stack, a text file, etc. Depends on the platform.
Take a look here:
http://forums.livecode.com/viewtopic.php?f=9&t=10728
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Stack custom properties
Craig, I haven't done much work with splash screen applications, so I'm not sure how it works. Would it just be a blank stack that doesn't do anything, but then on preOpenStack, it just opens my main program and that's it? Or is there more I'm missing?
Also Tom, I'm making it for iOs (for now). I've decided against using text files and whatnot (done it before, but not for iOs systems - does it still work? Because that's a nice easy way to do it if it does work, and it should be cross platform too, right?)
Also Tom, I'm making it for iOs (for now). I've decided against using text files and whatnot (done it before, but not for iOs systems - does it still work? Because that's a nice easy way to do it if it does work, and it should be cross platform too, right?)
-
quailcreek
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Stack custom properties
Yep... absolutely works in iOS. I use it all the time. Remember to pass shutDown
Code: Select all
on preOpenStack
if the environment is not mobile then exit preOpenStack
put specialFolderPath("documents") & "/appState.txt" into tStatePath
if there is not a file tStatePath then
## Create and populate the State.txt file
open file tStatePath for write
write "1002" to file tStatePath -- pre-populate the txt file with the ID of cd 1
close file tStatePath
else
-- answer "There is a file appState.txt"
end if
## Restore the state of the Last Card opened
set the defaultFolder to specialFolderPath("Documents")
put line 1 of URL ("file:appState.txt") into tStateCardID
put line 3 of URL ("file:appState.txt") into tSelection
set the uCollection of this stack to line 4 of URL ("file:appState.txt")
set the uMainFolder of this stack to line 5 of URL ("file:appState.txt") -- "/B1/"
set the uHeaderField of this stack to line 6 of URL ("file:appState.txt") -- "Pre WWII Soldiers"
set the usubHeaderField of this stack to line 7 of URL ("file:appState.txt")
end preOpenStack
on shutdown
## set default folder to writeable directory on mobile
set the defaultFolder to specialFolderPath("Documents")
put the uCollection of this stack into line 4 of URL ("file:appState.txt")
put the uMainFolder of this stack into line 5 of URL ("file:appState.txt")
put the uHeaderField of this stack into line 6 of URL ("file:appState.txt")
put the usubHeaderField of this stack into line 7 of URL ("file:appState.txt")
pass shutdown
end shutdownTom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: Stack custom properties
Hi Tomquailcreek wrote:Yep... absolutely works in iOS. I use it all the time. Remember to pass shutDown
Code: Select all
on preOpenStack if the environment is not mobile then exit preOpenStack put specialFolderPath("documents") & "/appState.txt" into tStatePath if there is not a file tStatePath then ## Create and populate the State.txt file open file tStatePath for write write "1002" to file tStatePath -- pre-populate the txt file with the ID of cd 1 close file tStatePath else -- answer "There is a file appState.txt" end if ## Restore the state of the Last Card opened set the defaultFolder to specialFolderPath("Documents") put line 1 of URL ("file:appState.txt") into tStateCardID put line 3 of URL ("file:appState.txt") into tSelection set the uCollection of this stack to line 4 of URL ("file:appState.txt") set the uMainFolder of this stack to line 5 of URL ("file:appState.txt") -- "/B1/" set the uHeaderField of this stack to line 6 of URL ("file:appState.txt") -- "Pre WWII Soldiers" set the usubHeaderField of this stack to line 7 of URL ("file:appState.txt") end preOpenStack on shutdown ## set default folder to writeable directory on mobile set the defaultFolder to specialFolderPath("Documents") put the uCollection of this stack into line 4 of URL ("file:appState.txt") put the uMainFolder of this stack into line 5 of URL ("file:appState.txt") put the uHeaderField of this stack into line 6 of URL ("file:appState.txt") put the usubHeaderField of this stack into line 7 of URL ("file:appState.txt") pass shutdown end shutdown
I don't need the preferences to be updated that often - it's for Dropbox, so I just want to save the key and secret so that the user won't have to authorize it each time. I should just be able to have it check for the file in preOpenStack, and if it exists, load the Dropbox info, and if not have the user log onto Dropbox and authorize it, then save to the file for next time. And because of that, I won't need anything in the shutdown script, because nothing gets updated when they leave. Does that sound about right, or have I missed something fundamental with it?
Many thanks
Re: Stack custom properties
Hi Tom,
you are accessing the file six times here!
For efficiency and speed only access the file once, put it into a variable and use that one:
Same for you other handler, of course:
Collect all data in a variable first and then write to file "en bloc"!
Best
Klaus
Code: Select all
...
## Restore the state of the Last Card opened
set the defaultFolder to specialFolderPath("Documents")
put line 1 of URL ("file:appState.txt") into tStateCardID
put line 3 of URL ("file:appState.txt") into tSelection
set the uCollection of this stack to line 4 of URL ("file:appState.txt")
set the uMainFolder of this stack to line 5 of URL ("file:appState.txt") -- "/B1/"
set the uHeaderField of this stack to line 6 of URL ("file:appState.txt") -- "Pre WWII Soldiers"
set the usubHeaderField of this stack to line 7 of URL ("file:appState.txt")
...you are accessing the file six times here!
For efficiency and speed only access the file once, put it into a variable and use that one:
Code: Select all
...
## set the defaultFolder to specialFolderPath("Documents")
## Why messing with the default folder when you can have an absoulte pathname:
put specialFolderPath("documents") & "/appState.txt" into fPrefsFile
put url ("file:" & tPrefsFile") into tPrefs
put line 1 of tPrefs into tStateCardID
put line 3 of tPrefs into tSelection
set the uCollection of this stack to line 4 tPrefs
set the uMainFolder of this stack to line 5 of tPrefs
set the uHeaderField of this stack to line 6 of tPrefs
set the usubHeaderField of this stack to line 7 of tPrefs
...Same for you other handler, of course:
Collect all data in a variable first and then write to file "en bloc"!
Best
Klaus
-
quailcreek
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Stack custom properties
Good catch, Klaus. Thanks! I'll make the change.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
