0.1 second doesn't = 0.1 second !?

Bugs will be moved here once resolved.

Post » Tue Nov 10, 2015 10:44 am

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
Image

Code
Image
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 :shock:

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..... :o 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! https://www.youtube.com/watch?v=DfPeprQ7oGc

" 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
Chrome

Operating System and Service Pack
Windows 7 64 SP1

Construct 2 Version ID
r216 64bit
B
7
S
1
Posts: 43
Reputation: 513

Post » Tue Nov 10, 2015 12:30 pm

Closing as not a bug. See "Expecting math calculations to be exact" in common mis-used events and gotchas.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Tue Nov 10, 2015 3:21 pm

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?
B
7
S
1
Posts: 43
Reputation: 513

Post » Tue Nov 10, 2015 5:19 pm

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.
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Wed Nov 11, 2015 12:31 pm

The blog post includes the solution as well, which is to allow small ranges of values instead of expecting exact results.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Sun Dec 13, 2015 3:23 pm

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
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?
B
7
S
1
Posts: 43
Reputation: 513

Post » Sun Dec 13, 2015 4:17 pm

ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest