Notifications
Clear all
[Closed] Creating a digital clock
Nov 27, 2013 7:43 am
Hi
I am trying to create a script with timer for UI and with labels in the max. What i want to do is to stop the timer and 60 for seconds and update 1 for minutes. That part is done but can;t actually stop the seconds at 60 and restart the counter again. And I dont want to use another timer for the minutes as i am doing now but the seconds should affect the counter of the number of the minutes. Here is the code for it:
Rollout DigiClock "Digital Clock"
(
local sec,
min
timer SecTme "Tme" interval:1000
timer MinTme "MinTme" interval: 60000
label hour " Hr Mn Sc" align:#left
label dots " : :" across: 20 offset: [30,0] align:#center
label hrs "00" across:30 align:#center
label minuts "00" offset:[20,0]
label secs "01" offset:[40,0]
fn SecTime =
(
sec =(secs.text as integer)+1
if sec <10 then
(
secs.text = "0" +sec as string
) else
(
secs.text = sec as string
)
)
fn MinTime =
(
min =(minuts.text as integer)+1
if min <10 then
(
minuts.text = "0" +min as string
) else
(
minuts.text = min as string
)
)
On SecTme tick do
(
SecTime()
)
On MinTme tick do
(
MinTime()
)
)
createDialog DigiClock width:150
3 Replies
Nov 27, 2013 7:43 am
you can simplify things a bit using the mod function
Rollout DigiClock "Digital Clock"
(
local sec, min, newsec;
timer theTimer "theTime" interval:10;
label hour " Hr Mn Sc" align:#left
label dots " : :" across: 20 offset: [30,0] align:#center
label hrs "00" across:30 align:#center
label minuts "00" offset:[20,0]
label secs "01" offset:[40,0]
On theTimer tick do
(
sec = (secs.text as integer) + 1;
secs.text = sec as string;
newsec = mod sec 60;
if newsec == 0.0 then
(
secs.text = 0 as string;
min =(minuts.text as integer) + 1;
minuts.text = min as string
)
)
)
createDialog DigiClock width:150
I’ll leave it for you to add the hours and the preferred formating oh yeah It’s running a bit fast as I got bored waiting
Nov 27, 2013 7:43 am
Or…
http://msdn.microsoft.com/en-us/library/dd992632(v=vs.110).aspx
(.NET 4.0 and up)