Countdown

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
alfredomora
Posts: 2
Joined: Mon Aug 03, 2009 3:34 am

Countdown

Post by alfredomora » Mon Aug 03, 2009 3:42 am

Hi :-)

I want to make a countdown from 60 to 0, and I want to make it visual with a progress bar. Can you help me?

Greetings from Mexico,

Alfredo Mora Izaguirre

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Aug 03, 2009 5:59 am

Create a new stack, drag a progress bar and a button onto it. Select the pogress bar, and use the Inspector palette to set its name to "MyProgressBar", its startValue to 0 and its endValue to 60. Then set the name of the button to "Countdown" and set its script to:

Code: Select all

on mouseUp
  repeat with i = 0 to 59
    set the thumbPosition of scrollbar "MyProgressBar" to i
    put (60 - i) && "seconds left"
    wait 1 second
  end repeat
  set the thumbPosition of scrollbar "MyProgressBar" to 60
  answer "Your minute is up!"
end mouseUp
If the user needs to interact with the stack while the countdown is happening, then replace the line

Code: Select all

wait 1 second
with

Code: Select all

wait 1 second with messages
This way, other buttons can receve and handle events as the clock keeps ticking. So drag another button onto the stack and set its script to

Code: Select all

on mouseUp
  send "CancelCountdown" to button "Countdown"
end mouseUp
Next modify the script of button "Countdown" slightly to

Code: Select all

on mouseUp
  set the uStatus of me to "started"
  repeat with i = 0 to 59
    set the thumbPosition of scrollbar "MyProgressBar" to i
    put (60 - i) && "seconds left"
    wait 1 second with messages
    if the uStatus of me is "cancelled" then
      put "Cancel was clicked!"
      exit mouseUp
    end if
  end repeat
  set the thumbPosition of scrollbar "MyProgressBar" to 60
  put "Your minute is up!"
end mouseUp
on CancelCountdown
  set the uStatus of me to "cancelled"
end CancelCountdown
Now the clock is ticking, and you know how to stop it when the user clicks a button. That should get you on your way, I think ;-)

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

alfredomora
Posts: 2
Joined: Mon Aug 03, 2009 3:34 am

Thank you!

Post by alfredomora » Mon Aug 03, 2009 8:57 pm

Dear Jan,

Thank you very much, all works fine!

Greetings from Mexico,

Alfredo Mora Izaguirre

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Countdown

Post by Mag » Sat Jun 08, 2013 5:53 pm

Hi all,

I'm implementing this code, it works fine but it refreshes the message box only when I comment the line which changes the label of a button, the same if I put a line that changes the custom properties of the target button or if I want to update a progress bar.

Code: Select all

        repeat with i = 0 to 10
             put (10 - i) && "seconds left"
             -- set the label of button "timerButton" to (10 - i)
             wait 1 second with messages
        end repeat
Any advice?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Countdown

Post by jmburnod » Sat Jun 08, 2013 6:27 pm

Hi mag,
it refreshes the message box only when I comment the line which changes the label of a button
I test your script (LC 5.5.4) and it works. I can see the label change and i & "seconds left" in the messagebox

Best regards
Jean-Marc
https://alternatic.ch

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Countdown

Post by Simon » Sat Jun 08, 2013 8:56 pm

Hi Mag,
Works here in LC 6.0.0

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Countdown

Post by Mag » Sat Jun 08, 2013 11:28 pm

Oops, I apologize. I followed the advice of the grandmother (restart LiveCode) and everything started to work properly. Maybe I intoxicated the memory with my previous experiments. Thank you so much Simon and jmburnod, your posts convinced me to try again.

Post Reply