Page 1 of 1

Wait with messages

Posted: Fri Mar 12, 2010 9:14 pm
by ukaussie
Hi,

I have the following code associated with an icon. When the user hits the icon it disappears, randomly sets a new location and then shows itself. This happens while a countdown from 30 seconds to 0 occurs. When i don't have a 'wait' command it works fine. However, with the wait command inserted the timer stops counting down every time the icon is hit. I thought 'wait with messages' meant that other running scripts (i.e. the countdown) continued in the background? Or does that only work with a 'repeat'?

Code: Select all

global tScore, txLoc, tyLoc

on mousedown
   add 1 to tScore
   put tScore into field "scoreField"
   hide me
   put random(240) into txLoc
   put txLoc + 40 into txLoc
   put random(320) into tyLoc
   put tyLoc + 40 into tyLoc
   set the loc of me to txLoc,tyLoc
   wait 2 seconds with messages
   show me
end mousedown

Re: Wait with messages

Posted: Fri Mar 12, 2010 10:37 pm
by Klaus
Hi ukaussie,

use this:

Code: Select all

on mousedown
   GLOBAL tScore, txLoc, tyLoc
   add 1 to tScore
   put tScore into field "scoreField"
   hide me
   put random(240) into txLoc
   put txLoc + 40 into txLoc
   put random(320) into tyLoc
   put tyLoc + 40 into tyLoc
   set the loc of me to txLoc,tyLoc
   wait 2 seconds with messages
   show me
end mousedown
GLOBAL vars have to be declared in every handler where they are used!

If you declare them outside of the handler at the top of the script they will be treated as LOCAL vars.
Check the docs for "global".


Best from germany

Klaus

Re: Wait with messages

Posted: Fri Mar 12, 2010 10:51 pm
by ukaussie
Hi Klaus,

Thanks, but the variable type does not affect the wait statement. The same 'error' occurs whether they are global or local. Any more thoughts?

Grant.

Re: Wait with messages

Posted: Fri Mar 12, 2010 11:50 pm
by mwieder
Klaus-

Globals can be declared anywhere. That shouldn't affect things here.

Grant-

I just tried your code and it works fine. A 30-second timer continues to count down even while the icon is being hidden and displayed. Maybe there's something weird with your timer?

Re: Wait with messages

Posted: Sat Mar 13, 2010 12:11 am
by ukaussie
Hi mweider,

Here's my countdown code. See anything that might cause the problem?

Code: Select all

on mouseup
   global tScore, tTime
   put empty into tScore
   put 0 into field "scoreField"
   repeat with tTime = 30 down to 0
      put tTime into field "timeField"
       if tTime = 0 then wait 0 seconds with messages
      else wait 1 second with messages
   end repeat
   if tTime = 0 then answer "Well done!! You scored" && tScore with "Proceed to Level 3" as sheet
   go to card "Level3"
end mouseup

Re: Wait with messages

Posted: Sat Mar 13, 2010 12:26 am
by mwieder
Not sure, but you might be running into dueling "wait with messages" statements. When I tried your code I made a timer that looked something like

on countdown
subtract 1 from field "timeField"
if field "timeField" is not 0 then
send "countdown" to me in 1 second
end if
end countdown