How do I make a reliable counter?

Get help using Construct 2

Post » Sun Mar 27, 2016 7:47 am

Hello everyone!
For my project I need to measure the time as better as possible. I made a counter variable and Every Tick i Add dt to this variable. I thought that would do the trick but i was Wrong. When i try the game in a phone I realized that the time was actually slower than the real time. I think the time goes slow when the fps drop, but i thought that was what i was avoiding using the Dt function. I attached an image to show what i mean (Time has the same value as my counter and it should have the same value as Wall clock )
Thank you

Image
Last edited by tutyses on Sun Mar 27, 2016 9:23 am, edited 1 time in total.
B
11
S
1
Posts: 15
Reputation: 507

Post » Sun Mar 27, 2016 8:45 am

Time
- Can be modified by timescale
- Stops when window is unfocused/hidden
- May start slightly later than wallclock

Using dt to increment a variable should work well.

Otherwise, you can use time and wallclocktime directly as expressions directly as well.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Sun Mar 27, 2016 9:26 am

oosyrag, I uploaded the wrong screenshot, my bad. I edited it, I was trying to show you that i am using dt
Timescale is 1 and never change.
The window is always focused
And is not that it start a little later, as time goes by, the difference between the counter and the wallclock becomes Bigger and bigger. I tryied for 3 minutes and i had a 30 seconds of difference ! That is QUITE a lot
B
11
S
1
Posts: 15
Reputation: 507

Post » Sun Mar 27, 2016 5:36 pm

Do your counter variable and time match?

Seems like a workaround would just be to set your variable to wallclocktime every tick if that's what you are looking for.

I've also had scenarios where time falls behind wall clock when I run a very heavy loop - time can freeze but wall clock keeps going. I don't know how much other stuff you have going on in your project though.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Sun Mar 27, 2016 5:58 pm

Yes, my counter variable and time do match
It has some intensive moments because it s a falling blocks thingy and i have like 1000 collisions check per second ( I am trying to optimize that right now), but i will need a framerate independant counter even if i optimize it
I think i will try using wall clock but i would like to know why my counter and time are not working correcly, just to understand what is happening
B
11
S
1
Posts: 15
Reputation: 507

Post » Sun Mar 27, 2016 6:06 pm

Does your frame rate ever drop below 10fps? I think that will result in a discrepancy, although I'm not sure. Maybe someone else can confirm?
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Sun Mar 27, 2016 7:15 pm

I m testing it on pc with the debug mode on, fps are never lower than 30. Every time I close the project and i play it again, i have different fps, but in general fps are between 40 and 50 (In debug mode, if i play it without debug it works 60fps always). If i have 60 ticks per seconds, the time WORKS WELL, it only starts to separate from Wall Clock when fps are less than 60, if i have 30 ticks per seconds the difference is actually PRETTY big.
Should i upload the Capx?

Edit: I tested it for 150 seconds, the wall clock says 150 seconds and the system time says 135 seconds, thats 15 seconds of difference, and is like a 10% of difference, A LOT. Fps were between 37 and 45
B
11
S
1
Posts: 15
Reputation: 507

Post » Sun Mar 27, 2016 8:39 pm

I think the problem is the dt value! I dont know if what i am doing have sense. I Put 2 text object, one show FPS and the other one shows 1/dt. I thought the should have similar values, but they dont, they have VERY different values.
The text using &fps shows 30 fps, while the one using 1/dt is showing 60/59 fps, Why? It's like dt is having different values i dont understand

Image

Here is the capx, just in case
https://mega.nz/#!GM5AiQwI!5GBlNtrwdgxPiFDM3X9uuYC9vtmTR8HokSU-W9Lvg8k
B
11
S
1
Posts: 15
Reputation: 507

Post » Mon Mar 28, 2016 3:09 am

Ok, the last thing i did (Using 1/dt to see fps), probably doesnt make sense, i dont know why, but it happens in every project i tested, so it means it never gives the real fps value.
I m open to theories to explain this! im really curious
B
11
S
1
Posts: 15
Reputation: 507

Post » Mon Mar 28, 2016 7:18 am

Additional discussion here: timebug-or-missunderstanding_t170501
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438


Return to How do I....?

Who is online

Users browsing this forum: facecrime, zenox98 and 7 guests