I have some code which sets up a lot
of info in arrays etc which I want to run
only once when the app. starts.
At the moment it's on the main card
so runs each time a button is clicked
and I can't find anywhere to put it so
that it only runs once.
Read about "onpreOpen" and "on preOpen card"
but confused about its use.
Any clarification appreciated.
Using "onpreOpen"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Using "onpreOpen"
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
The 'definitive' run-only-once message is 'startup'- but this will only get sent to your standalone application, never in the IDE.
So we had better find another message. I tend to put this initialization code into the 'preOpenStack' handler of the first card of my main stack, and I'll usually throw in a quick check to see if everything was initialized yet or not.
Hope this helped,
Jan Schenkel.
So we had better find another message. I tend to put this initialization code into the 'preOpenStack' handler of the first card of my main stack, and I'll usually throw in a quick check to see if everything was initialized yet or not.
Code: Select all
on preOpenStack
global gSettingsArray
if the keys of gSettingsArray is empty then
put the seconds into gSettingsArray’"startupTime"]
...
end if
end preOpenStack
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
preOpenStack
Jan
What would I do without you?
I did think of using a variable to check if
the code had been run already.
I tried using the "preOpenStack" method but
found the disadvantage was that to debug
it the stack had to be closed then re-opened.
Rather annoying I found, so I think your suggested
method is better.
What would I do without you?
I did think of using a variable to check if
the code had been run already.
I tried using the "preOpenStack" method but
found the disadvantage was that to debug
it the stack had to be closed then re-opened.
Rather annoying I found, so I think your suggested
method is better.
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
You can also trigger events yourself - in this case, you would go to the first card iof your main stack, and then open the Message Box, type in and hit return.
If thye handler requires parameters, you can add them in the message box, just like you would call the handler from a piece of script.
Hope this helped,
Jan Schenkel.
Code: Select all
preOpenStack
If thye handler requires parameters, you can add them in the message box, just like you would call the handler from a piece of script.
Hope this helped,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com