Logical And &

Discussion and feedback on Construct 2

Post » Thu Jan 02, 2014 7:54 pm

It seems to think 2 & 4 = 1. when it should be 0. Also it thinks 2 & 6 is 1 when it should be 2. It looks like maybe "logical and" only cares about the first bit.

I'm trying to see if an array of things are on or off with a single number which should be easy with a logical AND. Is there a way to do an actual AND on the numbers?
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
65
S
17
G
5
Posts: 172
Reputation: 8,451

Post » Thu Jan 02, 2014 9:43 pm

You're thinking of "bitwise and". "&" in C2 expressions is "logical and" where 0 is false and nonzero is true.

That said you can do "bitwise and" with the browser object and the ExecJS expression.

For example setting some text to Browser.ExecJS("4&2") will give 0.
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Thu Jan 02, 2014 9:52 pm

Perfect thanks!   
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
65
S
17
G
5
Posts: 172
Reputation: 8,451

Post » Thu Jan 02, 2014 9:57 pm

Yan made a plug.
Image ImageImage
B
172
S
50
G
183
Posts: 8,442
Reputation: 115,603

Post » Wed Aug 26, 2015 10:13 pm

There's getbit and setbit which I didn't know about at the time... Those do exactly what I was trying to do and they're already system expressions.
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
65
S
17
G
5
Posts: 172
Reputation: 8,451


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 3 guests