Float bug i think.

0 favourites
  • 10 posts
From the Asset Store
Match same tiles with each other as fast as you can and earn more score during a limited time!
  • Ok i have a event every 1 seconds add 0.1 to global variable Speed,

    And have every tick set text "Speed: "&Speed but it keeps disapearing and sometimes reapears, it always dissapears at 0.2 and reapears at 0.4 then dissapears again.

    if i set "Speed: "&floor(Speed) it stays there displayed but obviously is rounded to an int so it only updates on whole numbers. And if i put "Speed: "&float(Speed) it still dissapears..

  • The text object doesn't display text if it's not big enough. Are you sure you resized your text object big enough? If so, can you post a .capx?

  • ok here you go

    mediafire.com

    just incase another link.

    dl.dropbox.com/u/44766364/RollerBallB1.capx

  • You can see from the picture below, the value the text field needs to show is very long.

    <img src="http://dl.dropbox.com/u/34306693/floaterr.png" border="0" />

    As you are only incrementing by 0.1 at a time, I would say this is not what you would expect to happen. FormatDecimal from CC would be useful here.

    Ashley will be able to say whether this is expected behavior or a bug.

  • Like I thought, the text object isn't big enough to display the actual number "3.6000000000002" as zenox showed.

    Computers cannot do fractional calculations with infinite precision, because that would require infinite computing power, so there are always small errors. Try setting the text object to:

    round(Speed * 10) / 10

    to only display one decimal place. In the next build I'll add some degree of rounding in the text object itself so this doesn't happen.

  • Thanks that works great :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In the next build I'll add some degree of rounding in the text object itself so this doesn't happen.

    On one hand, I like that idea, but on the other, then the text object won't show the actual value and I'm concerned that could potentially be really frusterating when debugging.

    Maybe a property could be added to turn that on/off?

  • I think it's a good default, since you shouldn't rely on exact float comparisons anyway. However, the system str expression won't do any rounding, so if you want to see the un-rounded value you can do str(value).

  • Ah, ok. Happy there's a work around, then.

  • Or whay about adding to what decimal point we want rounded... 10ths/100ths/1000ths/ just an idea..

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