Accurate Time

Get help using Construct 2

Post » Thu Jan 26, 2012 5:37 pm

I created an event like this using the System-Time expression:

Every 1 seconds set text to Time.

I thought this would create a textbox shows a value which increments every second (1,2,3...). But in practice, the textbox value has a lag and values are increasingly off (1.008, 2.013, 3.033...). Why is there a lag and why does it get worse and worse?

Thanks from a newbie.
B
2
Posts: 5
Reputation: 260

Post » Thu Jan 26, 2012 5:53 pm

Because of delta-time probably, read this for more info: Delta time tutorial

You should replace the event with
Every tick >
-> Add 1*dt to varTime
-> Set text to str(varTime)

Someone correct me if there's anything wrong here
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Thu Jan 26, 2012 7:07 pm

Thanks for the reply, 7Soul. I also suspected that dt might solve my problem. However, your suggestion gives me a continuous counter. I'm looking for a counter that increments by seconds. And I'm not sure why I would use the expression 1*dt. It seems redundant. Did you mean something else?

I'm curious as to why Every X Seconds doesn't work. Is it a realtime timer, or is it an approximation? I feel like I'm under some basic misapprehension.
B
2
Posts: 5
Reputation: 260

Post » Thu Jan 26, 2012 7:27 pm

Try int(1*dt) I put the 1 just as a good practice. Changing it to 1000, for instance, would give you the milliseconds
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Jan 27, 2012 10:06 am

Well, I read the dt tutorial again and used their example to do some testing. I created 3 textboxes and the following events:




Which produced the following results.



You can see the timers which rely on "every tick" are in synch, whereas the one which relies on "every x seconds" is lagged (until the numbers from the right of the decimal carry over and then it catches up).

This was unexpected behavior for me. I guess I need a better understanding of frames. I am interested in this problem because I am creating a musical game where time is very important.bigbrad2012-01-27 10:09:49
B
2
Posts: 5
Reputation: 260

Post » Fri Jan 27, 2012 11:06 am

stupid question....why or better what for do you need a timer, that is exact to a milisecond?
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Fri Jan 27, 2012 1:12 pm

I am hoping to make a game where people will follow along to the tempo of music and tap buttons at the same time that the notes are played.
B
2
Posts: 5
Reputation: 260

Post » Fri Jan 27, 2012 4:34 pm

This is because a tick is faster than a second, so these events will run at different times. A tick, at 60 frames per second, happens 60 times in a second, as you would expect.

But now, tell me what you want to happen, because I don't understand :I
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Jan 27, 2012 4:50 pm

It think ticks are client dependent, ie a tick on a high speed four core processor might be shorter than on an old x86...

But maybe Ashley could answer this.
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Fri Jan 27, 2012 6:10 pm

I think I've got it now. Thanks for your help!
B
2
Posts: 5
Reputation: 260

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests