locked
make a countdown RRS feed

  • Question

  • Hello,

    I would like to now how it's possible to create a real countdown.

    Launch the program, I want the user to initialize the liquidation account and put paramettres he wants.

    He could put the hour, minute andsecond he wants.
    To pause, resume, and reset whenever he wants.

    Basically,I want to make a timer with rebourd account.

    I have a book and not many examples of the use of clock function.

    Can you help me?

    Thank you.


    absolu

    Sunday, February 10, 2013 6:02 PM

Answers

  • Finally, I opted for this view.

    Thank you for your advice ^ ^
     

    absolu

    If you could mark one of the answers as an answer, it would be appreciated, and would benefit anyone who stumbles upon this thread.
    • Marked as answer by absolu Friday, February 15, 2013 12:35 PM
    Friday, February 15, 2013 12:32 PM

All replies

  • A countdown will be for a fixed period of time, say 1 hour 10 minutes and 35 seconds.

    This is 60*60 + 60*10 + 35 = 4235 seconds = 4325000 ms (say variable countdownTime).

    When the timer start get the Clock.EllapsedMilliseconds, eg:

    startCountdown= Clock.EllapsedMilliseconds

    Then at any time in the future calculate the elapsed time since the countdown started

    elapsedTime = Clock.EllapsedMilliseconds - startCountdown

    Therefore the remaining time is

    remaingTime = countdownTime - elapsedTime

    When this is zero (or negative) you are done.

    You could use the Timer event to check this at fixed intervals, say 1 sec or 1000 ms.


    • Edited by litdev Sunday, February 10, 2013 6:13 PM
    • Proposed as answer by Nonki Takahashi Wednesday, February 13, 2013 5:24 AM
    Sunday, February 10, 2013 6:12 PM
  • Ok,

    I understand about, but it is the use of functions that I do not know well.

    There are:

    Timer.Pause ()
    Timer.Interval
    Timer.Tick
    display
    etc ...

    I do not have a strong example to understand their use.

    absolu

    Sunday, February 10, 2013 6:26 PM
  • OK, the timer is just another event that fires at a regular interval, it can be started and stoped.

    So we set the timer interval in ms and hook up the timer event to a subroutine.

    Timer.Interval = 1000
    Timer.Tick = OnTick
    
    Sub OnTick
      TextWindow.WriteLine("Timer Fired")
    EndSub

    We could also have buttons for example the pause and restart the timer using Timer.Pause() and Timer.Resume().

    Sunday, February 10, 2013 6:31 PM
  • I fumbled, but I tried this:


    For counter = 60 To 0 Step-1
      Program.Delay(1000) '1000 milliseconds = 1 second
      TextWindow.Write(counter)
      TextWindow.WriteLine(" secondes sont passées")
    EndFor


    Is this a good way?
    Because after I'm not sure how to implement the hours and minutes?


    absolu

    Sunday, February 10, 2013 9:47 PM
  • Your program works fine.  It is a good way to start creating the countdown that you want.  I would work internally (most of your program) in seconds or even ms.  Hours and minutes are then just a conversion provided to read and display to the user.

    You could write subroutines that convert between hours min and seconds to seconds and then back again.

    EDIT

    The problem with your method may be the Program.Delay.  This blocks anything else from happening while the timer is counting down.  Therefore all your program will do is just count down and nothing else can happen at the same time.  Therefore a Timer may be better.

    Sample type program:

    'Create a timer and set it paused
    Timer.Interval = 1000
    Timer.Pause()
    Timer.Tick = OnTick
    
    'Get user input
    TextWindow.WriteLine("Enter time in seconds")
    countdown = Math.Round(TextWindow.ReadNumber()) 'Make the time an integer
    TextWindow.Hide()
    Timer.Resume() 'Now start the timer
    
    'Create a ball for test - this could be a sprite in a game or whatever
    ball = Shapes.AddEllipse(20,20)
    ballX = 0
    ballY = 0
    
    'A main game loop
    While (countdown > 0)
      'Do anything you want during the countdown here
      'In this case just move a ball
      X = X+5
      Y = Y+5
      If (X > GraphicsWindow.Width) Then
        X = 0
      EndIf
      If (Y > GraphicsWindow.Height) Then
        Y = 0
      EndIf
      Shapes.Move(ball,X,Y)
      Program.Delay(20)
    EndWhile
    Timer.Pause() 'Stop the timer
    
    Sub OnTick
      countdown = countdown-1
      GraphicsWindow.Title = "Time remaining is "+countdown+" seconds"
    EndSub

    • Edited by litdev Sunday, February 10, 2013 10:30 PM
    Sunday, February 10, 2013 10:13 PM
  • For i = 60 To 0 Step - 1
      Program.Delay(1000)
      TextWindow.WriteLine(i)
      EndFor

    A spark to start a fire is necessary. But mainly you need dry kindling.

    Sunday, February 10, 2013 11:46 PM
    Answerer
  • Thank you for your explanations,

    Mathematically speaking, I understand, but I'm afraid I do not have the skills to turn that into lines of code.

    Could you help me please ?


    absolu

    Monday, February 11, 2013 11:39 AM
  • When you type the word timer is the searchwindow at the top of the forumpage, you find a number of forum entries with the word timer in it. Some threads are rather old (e.g. I saw a question about SB version 0.4) but you can find there a number of tips. 

    Hope this helps


    Jan [ WhTurner ] The Netherlands

    Monday, February 11, 2013 12:16 PM
    Answerer
  • Ok, but I watched several son and nothing that describes a true count down.

    We can not divert clok.hour, clock minute clock.second?

    The force from the level of a variable?

    genre:

    clock.hour = 0
    or
    a = 0
    clock.hour = a

    absolu

    Monday, February 11, 2013 5:14 PM
  • clock.hour reads the computerclock so you have to do:

    a=clock.hour

    textwindow.writeline(a)


    Jan [ WhTurner ] The Netherlands

    Monday, February 11, 2013 6:49 PM
    Answerer
  • Try the folowing program:

    deltah=2    'starttime
    deltam=1         ''
    deltas=10         ''
    deltat=3600*deltah+60*deltam+deltas
    Timer.Interval=1000
    Timer.Tick=update
    Sub update
      deltat=deltat-1
      h=math.Floor(deltat/3600)
      m=math.Floor(deltat/60)-60*h
      s=deltat-3600*h-60*m
    TextWindow.WriteLine(h+":"+m+":"+s)
    EndSub  


    Jan [ WhTurner ] The Netherlands


    Monday, February 11, 2013 10:34 PM
    Answerer
  • Hello,

    Here is one snippet:

    gw = GraphicsWindow.Width   
    gh = GraphicsWindow.Height



    GraphicsWindow.fontname = "DS-Digital"
      GraphicsWindow.FontSize      = 38
      GraphicsWindow.DrawText      ( 600, 20, " ")
      GraphicsWindow.BrushColor    = "RED"
     



    deltah=0    'starttime
    deltam=26         ''
    deltas=0         ''
    deltat=3600*deltah+60*deltam+deltas
    Timer.Interval=1000
    Timer.Tick=update




    Sub update
      deltat=deltat-1
      h=math.Floor(deltat/3600)
      m=math.Floor(deltat/60)-60*h
      s=deltat-3600*h-60*m
      GraphicsWindow.DrawText (240,170, h+":"+m+":"+s)
          
    EndSub



    What function is used to delete digits, to avoid overlap ?






    absolu

    Tuesday, February 12, 2013 8:46 AM
  • You have to draw a filled rectangle with background brushcolor (in your case White) over the text and then reset the brushcolor to Red. Thereafter you can draw the new text.

    Jan [ WhTurner ] The Netherlands

    Tuesday, February 12, 2013 10:55 AM
    Answerer
  • ok, I'll try.

    thank you

    absolu

    Tuesday, February 12, 2013 7:10 PM
  • Please start new threads for new questions - thanks.
    Tuesday, February 12, 2013 7:50 PM
  • Finally, I opted for this view.

    Thank you for your advice ^ ^


    GraphicsWindow.Width = 1000
    GraphicsWindow.Height = 300
    GraphicsWindow.Left = (Desktop.Width / 2) - (GraphicsWindow.Width / 2)
    GraphicsWindow.Top = (Desktop.Height / 2) - (GraphicsWindow.Height / 2)
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Title = "FINAL DECOMPTE"
    GraphicsWindow.BackgroundColor = "black"
    GraphicsWindow.BrushColor = "red"
    GraphicsWindow.FontSize = 250
    GraphicsWindow.FontName = "DS-Digital"

    deltah=0    'starttime
    deltam=26         ''
    deltas=0         ''
    deltat=3600*deltah+60*deltam+deltas
    Timer.Interval=1000
    Timer.Tick=update




    Sub update
      GraphicsWindow.Clear()
      deltat=deltat-1
      h=math.Floor(deltat/3600)
      m=math.Floor(deltat/60)-60*h
      s=deltat-3600*h-60*m
      GraphicsWindow.DrawText (150,20, h+":"+m+":"+s)
    EndSub
     

    absolu

    Wednesday, February 13, 2013 9:01 PM
  • Finally, I opted for this view.

    Thank you for your advice ^ ^
     

    absolu

    If you could mark one of the answers as an answer, it would be appreciated, and would benefit anyone who stumbles upon this thread.
    • Marked as answer by absolu Friday, February 15, 2013 12:35 PM
    Friday, February 15, 2013 12:32 PM
  • Hi,

    I come to ask you for help on this famous countdown.
    I want to put a data entry system: hh, m, s, with the input function. Then the countdown starts. From there, I would like to be able to stop (pause) a question to reset it to 0. Both function as a button, below the meter.

    What you see is what I'm trying to do?

    Can you help me?

    Thank you.

    absolu

    Saturday, February 23, 2013 7:45 PM
  • For the use of buttons you need to use the subcommands of the "Control" command (AddButton, ButtonClicked). For explanation of these commands see e.g. the SB-Manual of NoachanON in this forum.
    For the entry of a starttime you can use TextWindow.Read.
    You have to remove the GraphicsWindow.Clear command in your program as after the Clear the buttons are gone.
    You should try to experiment with these commands and ask here if you cannot solve specific problems.

    Jan [ WhTurner ] The Netherlands

    Monday, February 25, 2013 2:31 PM
    Answerer
  • Hello,

    Here is a little mod code with the arrow keys up and down.
    The principle works.

    I also have to change the size of the big typo + reading the scroll.

    DRW247

    For the pause button, I tried to change the text starts where it was paused, but it always starts from the beginning.
    And there is another setting that I would like to integrate the scroll, it's back to the line. Here, the text goes below the buttons. Is there a way to calibrate the linefeed?

    Thank you for your feedback and your help

    absolu

    Tuesday, March 26, 2013 10:01 PM
  • How about this?  SZT967-3

    "↑" ... run Up direction ,  "↓" ....run  Down direction ,"ǁ"  Pause or stop,

      "+","-" ... Speed Up Down,  .....  works if running.

    "<" ">"  character size Up Down. ..... works if running.

    *Note ; It was difficult to change the size of each line and adjust left position.

     So , I used an  easy way that is to use one text( add full text to a shape) 

     
    Tuesday, March 26, 2013 11:36 PM
    Answerer
  • Hello,

    The arrow keys work great, also the pause button.


    The idea of ​​a teleprompter, is to fill the read distance, it is necessary that the text is big enough. Functions change text size can go on the first table. It will make a quick layout to read later.


    You really need to keep the play button and pause.


    absolu

    Wednesday, March 27, 2013 7:37 AM
  • OK   how about this? 

      SZT967-4

    Wednesday, March 27, 2013 8:59 AM
    Answerer