Why this condition doesn't work?

Get help using Construct 2

Post » Mon May 19, 2014 10:16 pm

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" ?
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Mon May 19, 2014 10:46 pm

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!
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Tue May 20, 2014 12:23 am

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 : )
B
6
G
1
Posts: 28
Reputation: 458

Post » Tue May 20, 2014 11:55 am

Thank you !
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to How do I....?

Who is online

Users browsing this forum: warmty and 9 guests