0.1 second doesn't = 0.1 second !?

0 favourites
  • 7 posts
  • Problem Description

    Having an issue with a play time timer. I'm adding 0.1 to a variable "Play_Time" ever 0.1 seconds.

    This way I can exclude menu time from game time by checking to see if the menu is open before it adds time to the play time variable. I need milliseconds because It's a time based racing survival game where seconds aren't going to be enough to separate players on a leader board. However I'm getting weird numbers.

    What I get


    The disabled code just caused the Play_Time to stay at 0.7.. not what I expected either.

    What I expected would happen

    well... you know.. 0.1 second would be a nice round 0.1... how could it possibly equate to anything else <img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked">

    Recreating this issue

    I had another interesting issue when recreating the capx for public viewing.

    I did the add 0.1 per 0.1 seconds thing with the play_time variable, then set a value in an array (used to record multiple scores) to Play_Time, which always gives a raw, uninterpreted value such as 1.99999999865 when viewed through a text object (set text1.text to array(1) ).

    Mean while I let construct interpret Play_Time directly without the array by viewing its value through a text object, the same way i did with the array, (set text2.text to Play_Time).

    I used a button object to take a snapshot of the values.

    • The array received the value Play_Time and displayed it as 14.999999999999963
    • The text object, however, displayed the value for Play_Time as 15
    • My value for time display which I got from the array and converted into time showed 0:1410 (this is in minutes)

    I get the sense that the .99999999963 is something theoretical. It knows it should be absolute e.g. 1.0 but it can be seen behaving as a decimal when viewed through an array... however the moment you reinterpret the value from the array it switches back into a whole value..... <img src="{SMILIES_PATH}/icon_e_surprised.gif" alt=":o" title="Surprised"> like my time display, the .999etc became a 1 again when called on to be a 'used value' as opposed to a 'stored value'... i'm freaking out, it's the matrix man!

    " Time " & int(Scores.At(Scores.CurX)/60) & ":" & int(Scores.At(Scores.CurX)) - (int(Scores.At(Scores.CurX)/60))*60 & (Scores.At(Scores.CurX) - int(Scores.At(Scores.CurX)) )*10

    Demo capx

    https://www.dropbox.com/s/dziksi3to3781 ... .capx?dl=0

    Affected Browsers


    Operating System and Service Pack

    Windows 7 64 SP1

    Construct 2 Version ID

    r216 64bit

  • Closing as not a bug. See "Expecting math calculations to be exact" in common mis-used events and gotchas.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For example the number 0.1 is exact in base 10, but is a recurring decimal in base 2. This means rounding can happen in unexpected places, even if you think you're dealing with exact numbers.

    ok... fair enough.

    was very scared, ty

    So how do you do it then?

  • [quote:2sz57ylx]So how do you do it then?

    You could add 1 to Play_time instead of 0.1 and whenever you want to look at the value divide by 10.

  • The blog post includes the solution as well, which is to allow small ranges of values instead of expecting exact results.

  • I do add 1, problem is a add 1 every 0.1 seconds..

    I do expect fairly exact results, In fact after looking at the google play leader boards guide for developers, I've found that i need 0.00 seconds , ie, hundredths of seconds

    [quote:sdkokj4i]Time leaderboards present scores in hours / minutes / seconds / hundredths of a second format. You must submit scores as milliseconds, so 66032 would be interpreted as 1:06.03.

    1 minute 06 seconds 03 milliseconds

    They need times submitted as milliseconds. I don't think construct can handle milliseconds can it?

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