How do I make a reliable counter?

0 favourites
  • 10 posts
From the Asset Store
Make a displayed number gradually increase or decrease, making an impression of a real-time counting.
  • 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

  • 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.

  • 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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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?

  • 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

  • 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

    Here is the capx, just in case!GM5AiQwI!5GBlNtrwdgxPiFDM3X9uuYC9vtmTR8HokSU-W9Lvg8k

  • 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

  • Additional discussion here:

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)