Why this condition doesn't work?

0 favourites
  • 4 posts
  • Hi.

    In my project, I set a custom opacity on two wall objects : 50 and 70.

    "If object is opacity 50" works, but not "if object is opacity 70".

    This is weird. However If I do :

    "f object is opacity <71 and if object is opacity > 69"

    It works.

    I'm kind of puzzled. Any idea why it doesn't work with a single "equal" ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This has to do with how computers store numbers. I believe internally C2 uses a range of 0 to 1 for opacity, but has to convert the value to the 0 to 100 range. This leads to inaccuracies. You'll see many forum posts about checking exact numbers. It's generally best to assume a small range. Checking round(timeTravelable.Opacity) = 70 will also work.

    If you log the values of opacity in the Console, you see that the opacity in question is actually 69.999999, where as the other is 50.

    The joy of computer math!

  • Hi, the reason behind this is that opacity, believe it or not, does not go straight in 1, 2, 3, 4 numbers but for example from 1.1231 to 2.3424 then 3.4145 and so on with totally random values after a dot.

    You can work this out with System->Is between values.

    This would be something like:

    timeTravelable.opacity

    69

    71

    Try this and manipulate values to see if it works : )

  • Thank you !

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