Using "onpreOpen"

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

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Using "onpreOpen"

Post by bjb007 » Mon May 26, 2008 3:00 am

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.
Life is just a bowl of cherries.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon May 26, 2008 5:42 am

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.

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
Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

preOpenStack

Post by bjb007 » Mon May 26, 2008 6:00 am

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.
Life is just a bowl of cherries.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon May 26, 2008 11:53 am

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

Code: Select all

preOpenStack
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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply