Before preOpenStack [Solved]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Before preOpenStack [Solved]
Is there a way to use an handler before the preOpenStack, even when the code is in the main stack ?
I need to test if a file is on the operating system only once when the appli loads.
If not, I set the Preferences by default, otherwise I read them from the file "preferences.txt".
I don't want, each time I change from one stack to an other this test to occur.
Let me know if it's not clear enought...
Cheers, Jean-Paul.
I need to test if a file is on the operating system only once when the appli loads.
If not, I set the Preferences by default, otherwise I read them from the file "preferences.txt".
I don't want, each time I change from one stack to an other this test to occur.
Let me know if it's not clear enought...
Cheers, Jean-Paul.
Last edited by atout66 on Thu May 14, 2015 6:43 pm, edited 3 times in total.
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
Have a look at 'startUp' in the dictionary
Re: Before preOpenStack
Exactly what I was looking for...
Thanks a lot!
Thanks a lot!
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
Argh ! I talk to fast...
This startup handler does not create folder nor files to store user's data.
I suppose I must put this handler into the mainstack, right ?
Cheers, Jean-Paul.
This startup handler does not create folder nor files to store user's data.
I suppose I must put this handler into the mainstack, right ?
Cheers, Jean-Paul.
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
I try an answer message just after the <on startup> to see when appear this startup handler but nothing happens...
I also tried with breakpoints in the debugger without success.
Any idea will be much appreciated
Regards, Jean-Paul.
Code: Select all
answer "This is the startup handler running !"Any idea will be much appreciated
Regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
Mmm... something like this perhaps ?
Code: Select all
on openStack
if environment() = "mobile" then
put specialfolderpath("documents") & "/mystartpreferences" into thefile
if there is not a file thefile then
-- set all preferences to default
else
put URL ("file:" & thefile) into thelastPlace
-- set the preferences to the altered state
end if
end openStackRe: Before preOpenStack
It sounds nice Dixie but the handler is in an <openStack> of the mainStack.
So each time I navigate from one stack to an other, the handlers <preOpenStack> and <openStack> from the mainStack run and they would read the preferences.
For example, let say I have a tool palette, which is an independant stack (subStack) opened inside the mainStack.
If I close the tool palette, the message <preOpenStack> and <openStack> goes to the mainStack, even if it is already open (for sure it is, it's the main one!), because it gets the focus I suppose...
That's why I can't put the load preferences into a <preOpenStack> or <openStack> handler.
I'm going to think about a bypass or something like that; still searching the forum.
Thanks for your help, Jean-Paul.
So each time I navigate from one stack to an other, the handlers <preOpenStack> and <openStack> from the mainStack run and they would read the preferences.
For example, let say I have a tool palette, which is an independant stack (subStack) opened inside the mainStack.
If I close the tool palette, the message <preOpenStack> and <openStack> goes to the mainStack, even if it is already open (for sure it is, it's the main one!), because it gets the focus I suppose...
That's why I can't put the load preferences into a <preOpenStack> or <openStack> handler.
I'm going to think about a bypass or something like that; still searching the forum.
Thanks for your help, Jean-Paul.
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
Could someone try this to test ?
Placing in the code of the mainStack.
Please, let me know, for me, no message at all...
Code: Select all
on startup
answer "This is the startup handler running !"
end startupPlease, let me know, for me, no message at all...
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
Using a global ( a custom property would probably be better) you can set a flag to check what is the state of the preferences set up... in this case if the global 'prefsFlag' is empty then you would know that the stack is being opened for the first time in the session... that being so the 'prefsSetUp' handler would run..
When 'prefsSetUp' is run then say 1 is placed into the global prefsFlag... the next time the stack is opened it knows whether to load prefs or not... when you close the stack, because you are quitting your application then you can save your preferences whether they have been altered or not
When 'prefsSetUp' is run then say 1 is placed into the global prefsFlag... the next time the stack is opened it knows whether to load prefs or not... when you close the stack, because you are quitting your application then you can save your preferences whether they have been altered or not
Code: Select all
global prefsFlag
on openStack
if environment() = "mobile" then
if prefsFlag is empty then
prefsSetUp
end if
end if
end openStack
on openCard
end openCard
on prefsSetUp
put 1 into prefsFlag
put specialfolderpath("documents") & "/mystartpreferences" into thefile
if there is not a file thefile then
-- set your preferences to default
else
-- extract your prefs from the file and set things up
put URL ("file:" & thefile) into thelastPlace
end if
end prefsSetUp
on closeStack
put specialfolderpath("documents") & "/mystartpreferences" into thefile
-- so for example
put the short id of this card into URL ("file:" & thefile)
end closeStack
Re: Before preOpenStack
Your stack will not get a startup message in the IDE, LiveCode gets it first before it loads your stack. You will only get the message in a standalone.
The most common approach is to put the commands into a preOpenStack handler and put that handler into the script of the first card of the mainstack. LiveCode always opens that card first on startup so it will get the message. But the card script is not in the message path for other stacks, so they won't respond to it.
This way you will be able to read preferences in both the IDE and in the standalone.
The most common approach is to put the commands into a preOpenStack handler and put that handler into the script of the first card of the mainstack. LiveCode always opens that card first on startup so it will get the message. But the card script is not in the message path for other stacks, so they won't respond to it.
This way you will be able to read preferences in both the IDE and in the standalone.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Before preOpenStack
Thanks to all of you for your help 
@ Dixie I agree with you. I was thinking about something like that when I talk about bypass. Could be the simpliest way probably.
@ Jacqueline I like your approach and think I'm going to test it too.
I will compare both of them and let you know.
Regards, Jean-Paul.
@ Dixie I agree with you. I was thinking about something like that when I talk about bypass. Could be the simpliest way probably.
@ Jacqueline I like your approach and think I'm going to test it too.
I will compare both of them and let you know.
Regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.
Re: Before preOpenStack
OK, both methods work fine 
The Jacqueline's one avoid the use of a global var.
So now, I've got two ways to get the same thing.
Thanks to all of you for your help, Jean-Paul.
The Jacqueline's one avoid the use of a global var.
So now, I've got two ways to get the same thing.
Thanks to all of you for your help, Jean-Paul.
Discovering LiveCode Community 6.5.2.

