Making a traditional timer

For questions about using Classic.

Post » Mon Apr 30, 2012 6:32 am

Hello again. This one is a small issue, I swear!

I'd like to make a timer which looks more traditional. As in, after 60 seconds, it goes to: "1:00" and so on to show the minutes. I've got the timer aspect of it down. That part was pretty simple, but I can only get it to show seconds. So after it gets to 60 seconds, it doesn't show minutes, it just keeps going up in seconds.

tl;dr version: I'd like to make a timer which that looks like this: "1:00", not like this: "60". Is there a simple way to do this in Classic?

Any help would be appreciated.

Edit: Also, I have thought maybe something like this would work:

Have two separate texts, one would be the minute, and the other seconds. Each seconds reaches 60, I reset seconds, and add 1 to minutes.

... I was just hoping there was a more simple was is all.Jim152012-04-30 06:40:10
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Mon Apr 30, 2012 6:42 am

Like this:

minutes= int(seconds / 60)
seconds= seconds % 60

Set Text to minutes & ":" & seconds
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Apr 30, 2012 7:26 am

Well I just tried doing what you suggested, but I think I did it wrong. Here's a printscreen:



When I untoggle the 'Add 1 every 1000 milliseconds', the text goes haywire when I try to play. When I toggle it as shown in the screencap, it reads: "0:0"

I feel like I'm missing something obvious here...

Jim152012-04-30 07:27:53
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Mon Apr 30, 2012 1:24 pm

[QUOTE=Jim15] I feel like I'm missing something obvious here...[/QUOTE] Yes you are. You're missing a counter of the elapsed time. ROJO showed a way of displaying a value in a minute:second format, but without counting the time it will always read 0:0, of course. Also, don't change the variable that you use for counting. And how come that you were able to enter "int global('Seconds')/60" without an error message? There are brackets missing: "int( global('Seconds')/60 ) "

First, create a counter for the elapsed time, let's say "totaltime". Now let it count the time:
+Always
->Add TimeDelta to global('totaltime')

Then add the conversion:
->set global 'minutes' to int(global('totaltime') / 60)
->set global 'seconds' to global('totaltime') % 60

and finally show it:
-> Set text to global('minutes') & ":" & global('seconds')

Somewhere on these forums you will find my "clock" example, it shows the conversion for h:m:s and also shows how to display the time as an analog clock.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Mon Apr 30, 2012 7:34 pm

[QUOTE=tulamide] [QUOTE=Jim15] I feel like I'm missing something obvious here...[/QUOTE] Yes you are. You're missing a counter of the elapsed time. ROJO showed a way of displaying a value in a minute:second format, but without counting the time it will always read 0:0, of course. Also, don't change the variable that you use for counting. And how come that you were able to enter "int global('Seconds')/60" without an error message? There are brackets missing: "int( global('Seconds')/60 ) "

First, create a counter for the elapsed time, let's say "totaltime". Now let it count the time:
+Always
->Add TimeDelta to global('totaltime')

Then add the conversion:
->set global 'minutes' to int(global('totaltime') / 60)
->set global 'seconds' to global('totaltime') % 60

and finally show it:
-> Set text to global('minutes') & ":" & global('seconds')

Somewhere on these forums you will find my "clock" example, it shows the conversion for h:m:s and also shows how to display the time as an analog clock.[/QUOTE]

It's now working properly, thanks for the help!

Also, I'm unsure why "int global('Seconds')/60" worked. I'm using the newest version of Classic, so maybe that's a change that was made?

I'll look for your analog clock example since that's sort of what I'm going for. Thanks again!
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Tue May 01, 2012 4:00 pm

I know it can be hard to find especially older caps on this forum. So I had a look at my online database. Here is the analog clock:

http://www.mediafire.com/file/mkdnhwwzzym/watch.cap

Don't try to move the window, that functionality is broken, due to changes to the window object. The clock itself works.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed May 02, 2012 9:56 pm

[QUOTE=tulamide] I know it can be hard to find especially older caps on this forum. So I had a look at my online database. Here is the analog clock:

http://www.mediafire.com/file/mkdnhwwzzym/watch.cap

Don't try to move the window, that functionality is broken, due to changes to the window object. The clock itself works.[/QUOTE]

Thanks again!

... though I'm still confused about how to get that extra zero in there, I should be able to figure it out somehow.
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Wed May 02, 2012 10:36 pm

[QUOTE=Jim15]... though I'm still confused about how to get that extra zero in there, I should be able to figure it out somehow. [/QUOTE] There are various ways to make it.

For example, just combine two strings and use the expression Right()
If 'seconds' is a global number variable and 'strSeconds' a global text variable, then
+some trigger
-> System: Set 'strSeconds' to Right("00" & 'seconds', 2)
would first create a string like "001" and then take only the rightmost two letters -> "01"

Even easier is using ZeroPad():
+some trigger
-> System: Set 'strSeconds' to ZeroPad(global('seconds'), 2)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri May 04, 2012 8:35 am

[QUOTE=tulamide] [QUOTE=Jim15]... though I'm still confused about how to get that extra zero in there, I should be able to figure it out somehow. [/QUOTE] There are various ways to make it.

For example, just combine two strings and use the expression Right()
If 'seconds' is a global number variable and 'strSeconds' a global text variable, then
+some trigger
-> System: Set 'strSeconds' to Right("00" & 'seconds', 2)
would first create a string like "001" and then take only the rightmost two letters -> "01"

Even easier is using ZeroPad():
+some trigger
-> System: Set 'strSeconds' to ZeroPad(global('seconds'), 2)[/QUOTE]

It worked!

Thanks for all the help tulamide. My score system can now fully function thanks to you!
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Sun May 06, 2012 1:58 am

Edit: Never mindJim152012-05-06 08:37:59
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests