Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Countdown Timer

To be honest I don't think I have ever seen a visual countdown timer, had to write this the other day for a tournament. Due to the lack of time to write it I borrowed the numbers from White Lights clock (thats a lot to type out). Anyway if anyone ever needs a timer here you go
Code
@echo off
title Timer
color 0a
mode con cols=40 lines=8
setlocal enabledelayedexpansion
:starttime
    set /p starttime="Enter time in Minutes: "
    if %starttime% leq 0 (
        echo Invalid input.
        goto starttime
    )
    if %starttime% gtr 60 (
        echo Invalid input.
        goto starttime
    )
:main
    set mintime=%starttime%
    set sectime=0
    :mainloop
        cls
        call :display
        timeout /t 1 >nul
        if %sectime% geq 0 (
            set /a sectime=%sectime%-1
        )
        if %sectime% lss 0 (
            if %mintime% leq 0 (
            goto endtime
            ) else (
            set /a mintime=%mintime%-1
            set sectime=59
            )
        )
        goto mainloop
    :endtime
        cls
        echo TIMES UP!
        pause >nul
        goto starttime
:display
    set n1l1=      ÛÛ&set n2l1=ÛÛÛÛÛÛÛÛ&set n3l1=ÛÛÛÛÛÛÛÛ&set n4l1=ÛÛ    ÛÛ&set n5l1=ÛÛÛÛÛÛÛÛ&set n6l1=ÛÛÛÛÛÛÛÛ&set n7l1=ÛÛÛÛÛÛÛÛ&set n8l1=ÛÛÛÛÛÛÛÛ&set n9l1=ÛÛÛÛÛÛÛÛ&set n0l1=ÛÛÛÛÛÛÛÛ&set nxl1=:::
    set n1l2=      ÛÛ&set n2l2=      ÛÛ&set n3l2=      ÛÛ&set n4l2=ÛÛ    ÛÛ&set n5l2=ÛÛ      &set n6l2=ÛÛ      &set n7l2=      ÛÛ&set n8l2=ÛÛ    ÛÛ&set n9l2=ÛÛ    ÛÛ&set n0l2=ÛÛ    ÛÛ&set nxl2=:::
    set n1l3=      ÛÛ&set n2l3=      ÛÛ&set n3l3=      ÛÛ&set n4l3=ÛÛ    ÛÛ&set n5l3=ÛÛ      &set n6l3=ÛÛ      &set n7l3=      ÛÛ&set n8l3=ÛÛ    ÛÛ&set n9l3=ÛÛ    ÛÛ&set n0l3=ÛÛ    ÛÛ&set nxl3=:::
    set n1l4=      ÛÛ&set n2l4=ÛÛÛÛÛÛÛÛ&set n3l4=ÛÛÛÛÛÛÛÛ&set n4l4=ÛÛÛÛÛÛÛÛ&set n5l4=ÛÛÛÛÛÛÛÛ&set n6l4=ÛÛÛÛÛÛÛÛ&set n7l4=      ÛÛ&set n8l4=ÛÛÛÛÛÛÛÛ&set n9l4=ÛÛÛÛÛÛÛÛ&set n0l4=ÛÛ    ÛÛ&set nxl4=  
    set n1l5=      ÛÛ&set n2l5=ÛÛ      &set n3l5=      ÛÛ&set n4l5=      ÛÛ&set n5l5=      ÛÛ&set n6l5=ÛÛ    ÛÛ&set n7l5=      ÛÛ&set n8l5=ÛÛ    ÛÛ&set n9l5=      ÛÛ&set n0l5=ÛÛ    ÛÛ&set nxl5=:::
    set n1l6=      ÛÛ&set n2l6=ÛÛ      &set n3l6=      ÛÛ&set n4l6=      ÛÛ&set n5l6=      ÛÛ&set n6l6=ÛÛ    ÛÛ&set n7l6=      ÛÛ&set n8l6=ÛÛ    ÛÛ&set n9l6=      ÛÛ&set n0l6=ÛÛ    ÛÛ&set nxl6=:::
    set n1l7=      ÛÛ&set n2l7=ÛÛÛÛÛÛÛÛ&set n3l7=ÛÛÛÛÛÛÛÛ&set n4l7=      ÛÛ&set n5l7=ÛÛÛÛÛÛÛÛ&set n6l7=ÛÛÛÛÛÛÛÛ&set n7l7=      ÛÛ&set n8l7=ÛÛÛÛÛÛÛÛ&set n9l7=      ÛÛ&set n0l7=ÛÛÛÛÛÛÛÛ&set nxl7=:::
    if %mintime% geq 10 (
        set min1=%mintime:~0,1%
        ) else (
        set min1=0
        )
    set min2=%mintime:~-1,1%
    if %sectime% lss 10 (
        set sec1=0
        ) else (
        set sec1=%sectime:~0,1%
        )
    set sec2=%sectime:~-1,1%
    for /l %%a in (1,1,7) do (
        call echo %%n!min1!l%%a%% %%n!min2!l%%a%% %%nxl%%a%% %%n!sec1!l%%a%% %%n!sec2!l%%a%%
    )
goto :eof
Just in case its mutilated by the forum parsing here is a pastebin.

EDIT: Thanks to boosted fixing what I was to lazy to, it is now more accurate and does a full minute instead of losing 1 second off of every minute.
Looks good. Simple and effective just the way I like it.
There's no place like ~/
(May 27, 2015 03:17 PM)b00st3d Wrote:  Looks good. Simple and effective just the way I like it.

Not sure how accurate it is, it may be losing a second from every minute so if you set if for an hour you may only be getting 59 minutes.
(May 29, 2015 10:35 PM)Nakamoto. Wrote:  Not sure how accurate it is, it may be losing a second from every minute so if you set if for an hour you may only be getting 59 minutes.

Didn't really read the code but if you could you could use a real timer, not bat no offence and use it for hour and if your guess is right use some sort of
Code
set /a SecondsVariableThing=%SecondsVariableThing% - 1
(May 30, 2015 04:32 AM)Advertisement Wrote:  Didn't really read the code but if you could you could use a real timer, not bat no offence and use it for hour and if your guess is right use some sort of
Code
set /a SecondsVariableThing=%SecondsVariableThing% - 1

I could but the purpose I wrote it for it isnt required to be super accurate, so I see no sense for me to sit for an hour to test it.
I didn't see it at first but this should be set at 60 rather than 59 because it immediately changes from 0 to 59 then waits a sec to change to 58. You could also check if %sectime% LSS 0 and leave the below line the same.

Code
set /a mintime=%mintime%-1
            set sectime=59
There's no place like ~/
Looks really awesome :) Sadly I had to exchange the unicode chars because my Windows already supports Unicode in Batch scripts,
that's why I just saw a bunch of weird chars at the first time starting it.
Great job man! I would +rep you if I could :-/

(English is not my native english, that's why most posts contain some mistakes. Thank you for understanding.)
(May 30, 2015 07:14 AM)b00st3d Wrote:  I didn't see it at first but this should be set at 60 rather than 59 because it immediately changes from 0 to 59 then waits a sec to change to 58. You could also check if %sectime% LSS 0 and leave the below line the same.

Code
set /a mintime=%mintime%-1
            set sectime=59

Changing the LEQ to LSS doesn't work, it break the script and I don't like seeing a 60 there for a second, doesn't seem clocky.
(Jun 1, 2015 12:56 PM)Nakamoto. Wrote:  Changing the LEQ to LSS doesn't work, it break the script and I don't like seeing a 60 there for a second, doesn't seem clocky.

It does work. You just need to change if %sectime% gtr 0 to GEQ. see below for an updated mainloop

Code
:mainloop
      cls
      call :display
      timeout /t 1 >nul
      if %sectime% geq 0 (
      set /a sectime=%sectime%-1
      )
      if %sectime% lss 0 (
      if %mintime% leq 0 (
            goto endtime
      ) else (
      set /a mintime=%mintime%-1
      set sectime=59
      )
      )
      goto mainloop
There's no place like ~/
(Jun 1, 2015 01:21 PM)b00st3d Wrote:  It does work. You just need to change if %sectime% gtr 0 to GEQ. see below for an updated mainloop

Code
:mainloop
      cls
      call :display
      timeout /t 1 >nul
      if %sectime% geq 0 (
      set /a sectime=%sectime%-1
      )
      if %sectime% lss 0 (
      if %mintime% leq 0 (
      goto endtime
      ) else (
      set /a mintime=%mintime%-1
      set sectime=59
      )
      )
      goto mainloop
Didn't cross my mind to change both but I guess it does work lol. On a side note although I tried to make it idiot proof I didn't think to cover every base of someone that might try to break it like myself.
if you enter a number followed by a letter it sets the mintime to the number then starts the sec time at 0 goes to 59 and goes a whole minute before mintime changes at all.
Example 4a makes it read 4:00 a second later its 4:59, no real reason to try and fix it, not a pressing matter.
Very nice work, this works perfectly.
very good timer thanks for sharing ^_^


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Iera NamhorunOct 6, 2018 06:28 PM 4 225 Oct 6, 2018 06:28 PM
Last Post: 0xDEAD10CC
[Java] by integrationLLCSep 19, 2017 06:44 PM 3 110 Sep 19, 2017 06:44 PM
Last Post: Charger
[Shell] by Elite Hacker 69Dec 24, 2015 04:46 PM 3 278 Dec 24, 2015 04:46 PM
Last Post: b00st3d