Page 1 of 1
PreOpenCard
Posted: Fri Jun 07, 2013 4:35 am
by sandybassett
I see mentioned On Openstack and PreOpenCard and I'm guessing this has to do just with the first card where you do some housekeeping preparation invisible to the user. Is that right? If so what seems to be best practice with this?
Re: PreOpenCard
Posted: Fri Jun 07, 2013 5:01 am
by icouto
I'm not too sure I understand your question, but I'll try to help anyway
The preOpenStack and openStack messages are sent when a stack opens,
once.
The preOpenCard and openCard messages are sent whenever a card opens. If the user navigates around your stack, going from one card to another and back again, these messages get sent several times - every time the user enters/returns to a card.
Does that help?
Re: PreOpenCard
Posted: Fri Jun 07, 2013 10:09 am
by Klaus
Hi Sandy,
please check these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: PreOpenCard
Posted: Fri Jun 07, 2013 3:06 pm
by sandybassett
Thanks icouto; so it seems that PreOpenCard is not a place (card) but an event (running some commands and settings before anything gets started) which might be the right place to declare global variables and open SQLite etc.
Thanks Klaus that's a big help to me generally (don't know yet if it covers preopencard). A problem I'm having getting started with LC is that I'm a very left-brained linear type person and jumping all around the place (tutorials, resources, dictionary, etc) leaves me hanging with lots of unconnected bits of knowledge then trying to put them together to make sense. Maybe that set of conferences will help me do that.
Re: PreOpenCard
Posted: Fri Jun 07, 2013 4:39 pm
by dunbarx
Sandy.
..."PreOpenCard is not a place (card) but an event ..."
Exactly.
Whichever side of the brain you use, "preOpenCard" is a message, not an object, like a card. You simply must know about this sort of thing. You used the term 'event", and broadly, that is what LC is all about, engine and user invoked events that are trapped and handled by scripts.
But you will find that a little practice puts these all in their rightful places, and like learning to read, very soon you simply can. This is advice from someone who uses neither side of his brain at all.
Craig Newman
Re: PreOpenCard
Posted: Fri Jun 07, 2013 5:39 pm
by mwieder
Sandy-
Just ignore what Craig said. Both sides of his brain are fully operational.
At any rate, LiveCode doesn't have what you might consider a "linear" or "procedural" model for coding. Rather, it's event-driven. Think of "messages" and "events" as being the same thing. When the user clicks on a button, the button generates "mouseDown" and "mouseUp" events. You can write handlers for these messages in the button script or you can place them farther down the object hierarchy.
Code: Select all
on mouseUp
answer "you rang?"
end mouseUp
The openX and preOpenX messages are a bit more complicated to explain in terms of when they're fired off. Common practice is to place the openStack and preOpenStack handlers in the script of the first card in the stack in order to help stay out of trouble.
Code: Select all
-- in the script of card 1
on preOpenStack
-- do some things here *before* the stack appears on the screen
end preOpenStack
Re: PreOpenCard
Posted: Fri Jun 07, 2013 6:04 pm
by dunbarx
Sandy.
Ignore what Mark said. He is only a gifted programmer and inspiring teacher.
Craig Newman
Re: PreOpenCard
Posted: Sat Jun 08, 2013 12:21 pm
by andrewferguson
preOpenCard is sent to a card before it appears on the screen.
openCard is sent to a card once it has appeared on the screen.
Also, there is preOpenStack and openStack, which are sent when the stack is opened, not the card.
Andrew