Hi,
I am using the "send" command to run a little timer (counting from 60 down
to 0) as follows:
on openCard
put empty into field id 1008
put 60 into timer
put false into halt
updateTimer
end openCard
on mouseDown
put timer into field id 1008
if the mouseLoc is within the rectangle of button id 1012 then answer
"hello"
end mouseDown
on updateTimer
if halt = false then
put timer into field "timer"
put timer - 1 into timer
if timer < 0 then put true into halt
if halt = false then send "updateTimer" to me in 1 second
end if
end updateTimer
This makes updateTimer unpleasantly recursive but anyway...
The value of the timer is available within the card script that contains the
handler "updateTimer" but I would like
A) the timer to run smoothly when other events occur (in this case,
mouseDown) and
B) to be able to access the value of timer from other objects e.g. buttons
on the same card or on other cards. In essence, I want to run concurrent
processes as you can in Scratch. Is there a way of doing this in LiveCode
without it getting unreasonably complicated?
Here's hoping you can help.
Including a Timer
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Including a Timer
Hi.
There is no way for the scripts you wrote to know what is going on in the others. I mean specifically the variables "halt" and "timer".
This is a quick solution, and not the best, but I am driving now, and cannot do better.
Put this in the card script. You need to give each script access to common variables.
Craig Newman
There is no way for the scripts you wrote to know what is going on in the others. I mean specifically the variables "halt" and "timer".
This is a quick solution, and not the best, but I am driving now, and cannot do better.
Put this in the card script. You need to give each script access to common variables.
Code: Select all
global timer, halt
on openCard
put empty into field 1
put 60 into timer
put false into halt
updateTimer
end openCard
on updateTimer
if halt = false then
put timer into field "timer"
put timer - 1 into timer
if timer < 0 then put true into halt
if halt = false then send "updateTimer" to me in 1 second
end if
end updateTimer