Wait with messages

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
ukaussie
Posts: 23
Joined: Mon Sep 28, 2009 9:04 pm

Wait with messages

Post by ukaussie » Fri Mar 12, 2010 9:14 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Wait with messages

Post by Klaus » Fri Mar 12, 2010 10:37 pm

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

ukaussie
Posts: 23
Joined: Mon Sep 28, 2009 9:04 pm

Re: Wait with messages

Post by ukaussie » Fri Mar 12, 2010 10:51 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Wait with messages

Post by mwieder » Fri Mar 12, 2010 11:50 pm

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?

ukaussie
Posts: 23
Joined: Mon Sep 28, 2009 9:04 pm

Re: Wait with messages

Post by ukaussie » Sat Mar 13, 2010 12:11 am

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Wait with messages

Post by mwieder » Sat Mar 13, 2010 12:26 am

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

Post Reply