Football game like time

Get help using Construct 2

Post » Sat Jun 23, 2012 2:15 am

Hey you guys!
I ran into a problam and I do need your help.

As the title says I want to make a Textfield which "holds" the time so it can displays it in a soccer time like way 00:00
What i got so far is that every second "1" is added to a textfield.
So that after 2 Minutes 120 is written.

My problems now are:
- how do I show the time in the specific format eg. 00:00
if the program itself is not capable of doing this
- which is the best plugin to achieve this

I actually tried alot and came accross a solution which I am not fully able to program.
I could make 2 textboxes. One holding the Minutes and the other one holding the seconds.
For the minute box I set: every 60 seconds add 1 to textbox. works out.
For the seconds box i set: every second add 1 to textbox... BUT now i need to tell the program that if above 59 start again from 0. ... and i cant make it work. I simply dont know where to put the if statement...

so if someone has a solution or an idea, please share.

First post first big problem right :-)
Have a nice day!
B
4
Posts: 2
Reputation: 329

Post » Sat Jun 23, 2012 11:20 am

You were on the right track, no need for plugins here. I made an example for you, hope it helps. Feel free to ask if there's something you don't understand.

FootballTimer.capx (r95)

(Edit: Mipey's way is better, check next .capx instead)
Nimtrix2012-06-23 12:34:51
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sat Jun 23, 2012 12:10 pm

I have a bad habit called fixing things that ain't broken... Bear with me!

See system expressions in the manual here
Notably:
time - counts time since the game started, includes timescale
wallclocktime - counts REAL time, no timescale
zeropad - pads a number with ceros

Why time or wallclocktime expressions? Because adding dt every tick actually may not be accurate, so I suggest keeping track of the time instead. When you start the counter, add current time to a variable. For countdown, add time + seconds. Then every tick you display variable-time and it shows seconds that passed.

If you want more precise timing, down to tenths or hundredhs of seconds, you can use the dt counter. Within one second, the inaccuracy is not that big anyway.

How to display time as minutes and seconds? Easy...
Set text to zeropad(2,floor(time/60)) & ":" & zeropad(2,time%60)
The first one shows minutes, padded by leaded zero when needed. Floor is there to ensure it is a whole number.
The middle one is just there for aestethic purposes. :P
The last one shows seconds, padded by leading zero.

I think, at least.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Jun 23, 2012 12:27 pm

[QUOTE=Mipey]zeropad - pads a number with ceros[/QUOTE]

@Mipey, thanks for mentioning that, was looking for an expression like this, but must have missed it. Will be useful in the future.

Updated .capx with zeropad: FootballTimer2.capx

I would use timescale for testing, since it allows the fast forwarding events to check that it all works (without staring at the timer for a minute). Change it to 'wallclocktime' if you want to.Nimtrix2012-06-23 12:33:01
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sun Jun 24, 2012 11:10 am

Thank you guys very much! The explanation and file were really helpful for me. I even understand it :-).

But as I tested the difference between "time" and "wallclocktime" I noticed a discrepancy.
In 2 minutes the time expression actually runs 6 seconds slower than wallclocktime. I don't know if you noticed it.

Beside that, thank's again :-)
B
4
Posts: 2
Reputation: 329

Post » Sun Jun 24, 2012 11:24 am

The discrepancy is due to the timescaling. Read about delta-time and framerate independence in this tutorial.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: Braus and 15 guests