Hope that you can help me
Resume Timer - New Question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Resume Timer - New Question
Hello, I already program a timer that counts down and I can make that the timer pauses with a button but I don´t know how can I do a button that resumes the timer.
Hope that you can help me

Hope that you can help me
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
Hi L.Coder
Creating a 'resume' functionality depends on how you coded the 'pause' - so can you share your code?
Kind regards
Dave
EDIT: and also depends on your timer code so can you share that too?
Creating a 'resume' functionality depends on how you coded the 'pause' - so can you share your code?
Kind regards
Dave
EDIT: and also depends on your timer code so can you share that too?
"...this is not the code you are looking for..."
Re: Resume Timer - New Question
Of Curse, first is the code of the timer and then is the pause.
thanks a lot Dave, I hope that you can help me.
thanks a lot Dave, I hope that you can help me.
Code: Select all
on mouseUp
put fld “timerDisplay"into CountTimer
put CountTimer into fld "timerDisplay"
send "UpdateTimer" to me in 1 second
end mouseUp
on UpdateWork
subtract 1 from CountTimer
put CountTimer into fld "timerDisplay"
if CountTimer>0 then
send "UpdateWork" to me in 1 second
else
wait 0.3 seconds
send "UpdateRest" to me in 1 second
end if
end UpdateWorkCode: Select all
on mouseUp
if the visible of me is true then
repeat for each line i in the pendingMessages
cancel (item 1 of i)
end repeat
end if
end mouseUp
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
Hi l.coder
One of the nice things about a great coding tool like LiveCode is that there are so many different ways to 'skin a cat' - and how you write a solution to a task in the morning might be different to how you write it in the evening ... here is a solid and clunky (but easy to grasp!) way to handle pause and resume:
All the code should go in your card and relevant buttons only have to call the startCounter, runCounter, pauseCounter and resumeCounter handlers. Again this is just how I wrote it to show the technique of using 'send in time' together with control of script local variables (sCounter and sPaused)
One of the nice things about a great coding tool like LiveCode is that there are so many different ways to 'skin a cat' - and how you write a solution to a task in the morning might be different to how you write it in the evening ... here is a solid and clunky (but easy to grasp!) way to handle pause and resume:
Code: Select all
local sCounter,sPaused
on startCounter
put empty into sPaused
put 10 into sCounter
put sCounter && "seconds remaining" into fld "fldTimerDisplay"
send runCounter to me in 1 second
end startCounter
on runCounter
if sPaused is empty then
if sCounter > 1 then
subtract 1 from sCounter
put sCounter && "seconds remaining" into fld "fldTimerDisplay"
send runCounter to me in 1 second
else
put "Time's up!" into fld "fldTimerDisplay"
end if
end if
end runCounter
on pauseCounter
put true into sPaused
end pauseCounter
on resumeCounter
put empty into sPaused
send runCounter to me in 1 second
end resumeCounter"...this is not the code you are looking for..."
Re: Resume Timer - New Question
Thanks a lot Dave! I did it, but when I press the button puts "seconds remaining" in the fld. And I don´t know why
I´m too lost.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
Hi l.coder - can you describe what you did, what buttons and fields you have, what handlers they are calling, what code you have inside those handlers - and lastly can you describe how you think the system SHOULD be working and exactly WHERE it is breaking down
The reason I'm asking you for these things is that it may well be that writing all these descriptions will lead to enlightenment!
Good luck!
Dave
The reason I'm asking you for these things is that it may well be that writing all these descriptions will lead to enlightenment!
Good luck!
Dave
"...this is not the code you are looking for..."
Re: Resume Timer - New Question
Yes, sure.
Here is the code of the play
Here is my pause code:
I deleted my resume code, because i tried to fix it but I only made it worse.
There are 2 timers, you can see that when the first one ends the other starts.
What I want to do is that if I press pause, the procedure stops but if I press resume continue as normal.
Here is the code of the play
Code: Select all
local CountTimer
local CountRest
local Repeat_Times
local UpdateRest
local UpdateWork
local Opciones
on mouseUp
put 30 into CountTimer
put 20 into CountRest
put CountTimer into fld "tTimer"
put CountRest into fld "tClock"
send "UpdateCount1" to me in 1 second
end mouseUp
on UpdateCount2
subtract 1 from CountRest
put CountRest into fld "tRest"
if CountRest>0 then
send "UpdateRest" to me in 1 second
else
exit UpdateRest
end if
end UpdateCount2
on UpdateCount1
subtract 1 from CountTimer
put CountTimer into fld "tWork"
if CountTimer>0 then
send "UpdateCount1" to me in 1 second
else
wait 0.3 seconds
send "UpdateCount2" to me in 1 second
end if
end UpdateCount1
Here is my pause code:
Code: Select all
local VariableStart
on mouseUp
put true into VariableStart
if the visible of me is true then
repeat for each line i in the pendingMessages
cancel (item 1 of i)
end repeat
end if
end mouseUp
There are 2 timers, you can see that when the first one ends the other starts.
What I want to do is that if I press pause, the procedure stops but if I press resume continue as normal.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
hi l.coder - did you try out the code I uploaded for you? Did the pause and resume work for you? can you see why it worked and why deleting the pendingmessages (at least the way you are doing it) won't allow a resume?
Kind regards
Dave
Kind regards
Dave
"...this is not the code you are looking for..."
Re: Resume Timer - New Question
Hi Dave, Yes I did it in a new stack.
I copied & pasted it to prove, and happened what I told you:when I press the button appears "seconds remaining".
Do you know another way to do this? I tried basicly all that I know but maybe It´s not enough.
P.S Thanks a lot for help me.
Regards.
I copied & pasted it to prove, and happened what I told you:when I press the button appears "seconds remaining".
Do you know another way to do this? I tried basicly all that I know but maybe It´s not enough.
P.S Thanks a lot for help me.
Regards.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
Hi l.coder - try the attached stack (which has the same code as I posted earlier...)
Kind regards
Dave
Kind regards
Dave
"...this is not the code you are looking for..."
Re: Resume Timer - New Question
Hi Dave, Thanks a Lot! really. You helped me a lot, I solved the problem so well, (actually you did it).
Best Regards and thanks again.

Best Regards and thanks again.
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Resume Timer - New Question
Great news!
For the benefit of others on the forum can you tell us what the 'aha' moment was and/or what advice you would give for the future?
Kind regards
Dave
For the benefit of others on the forum can you tell us what the 'aha' moment was and/or what advice you would give for the future?
Kind regards
Dave
"...this is not the code you are looking for..."
Re: Resume Timer - New Question
The variable helps me a lot & one advice will be: READ AND STUDY THE CODE As much as you can.
Thank you again Dave.
Thank you again Dave.