openCard seems to be acting like preOpenCard

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm

openCard seems to be acting like preOpenCard

Post by DirkArnold » Tue Jun 14, 2011 8:43 am

Hello.

I'm working on a quiz results page with an animated bar that displays the results. (The numbers tick up in a field and a graphical bar grows until the number of correct answers is reached.) It works fine when I run the script from the Code Editor window but when the card is opened by a Go or Open command (I've tried both) after the quiz finishes, the correct score and graphical bar are displayed, but the animation doesn't run. It's as if the animation is happening pre-Open... I've tried adding a Wait command to the on openCard handler, but oddly that just keeps the Quiz card on the screen longer, which doesn't make sense to me either.

The only hitch might be that the Results card is in a different (already open) stack... the main stack. The quiz stack isn't a substack but it's listed in the Stack Files in the Stack Inspector. Code highlights follow:

when the quiz is finished...

Code: Select all

 Open card "Results" of stack "MainNavigation"
then after declaring my vars on the Results card, there's this:

Code: Select all

on openCard
   displayResults gScore [gCurrentChapter]
end openCard

on displayResults pNumberRight
   --(animation stuff goes here; works fine when run in Code Editor. Also when opening the card for the first time from the Application Browser.
end displayResults
It seems simple enough. I've made sure in my testing that the card was freshly opening for the first time; I've also tried running with the Development Tools suspended. Is there a better way to make something happen on its own after a card opens?

Thoughts? Thanks! --Dirk

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: openCard seems to be acting like preOpenCard

Post by bn » Tue Jun 14, 2011 9:55 am

Hi Dirk,

could it be that your animation runs too fast to see? Without seeing the animation script it is difficult to tell. Try a wait in the animation and see if it helps, like "wait 50 milliseconds with messages" in the repeat loop.

To detach a handler from the calling handler, i.e. letting the calling handler finish before executing a handler that was called in that handler you can issue:

Code: Select all

on openCard
   send  displayResults gScore [gCurrentChapter] to me in 0 milliseconds
end openCard

now the opencard handler will finish first and then the displayResults handler is executed.

Kind regards

Bernd

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: openCard seems to be acting like preOpenCard

Post by jacque » Tue Jun 14, 2011 4:53 pm

Is the screen locked when you go to the card? If so, it won't unlock until all messages are done processing. I suspect the animation is running, but behind a locked screen. Bernd's suggestion will overcome that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

DirkArnold
Posts: 15
Joined: Sat May 14, 2011 11:35 pm

Re: openCard seems to be acting like preOpenCard

Post by DirkArnold » Tue Jun 14, 2011 6:25 pm

Bernd's tip for "send"ing the handler worked. I just had to enclose the message in quotes because of the parameters.

(I left out the animation bit to keep my post from overly long, but there is a wait in the loop. I tried adding "with messages" but it didn't make any difference.)

Jacque, I didn't explicitly lock the screen but it sure was acting like you described...

Thank you both... on to my next challenge!

--Dirk

Post Reply