The OR operator is not working!

Bugs will be moved here once resolved.

Post » Thu Dec 29, 2011 2:19 pm

Of course there is a conditional expression.
Check this manual article.

[quote]?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false
e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".
The condition counts as true if it is non-zero, and false if it is zero.[/quote]

Also the bug Ashley talks about is probably not the OR condition as you expect it.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Thu Dec 29, 2011 2:47 pm

[QUOTE=Kyatric] Of course there is a conditional expression.
Check this manual article.

[quote]?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false
e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".
The condition counts as true if it is non-zero, and false if it is zero.[/quote]

Also the bug Ashley talks about is probably not the OR condition as you expect it.[/QUOTE]

Are you on topic here? I want to run the event IF the AnimationName of Block is any of the 4 following strings.
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Thu Dec 29, 2011 3:47 pm

Hmm, there might be an operator precedence bug - does this work?

(Block.AnimationName = "block1") | (Block.AnimationName = "block3") | (Block.AnimationName = "block13") | (Block.AnimationName = "block14")
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Thu Dec 29, 2011 4:23 pm

[QUOTE=Ashley] Hmm, there might be an operator precedence bug - does this work?

(Block.AnimationName = "block1") | (Block.AnimationName = "block3") | (Block.AnimationName = "block13") | (Block.AnimationName = "block14")[/QUOTE]

nope.
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Thu Dec 29, 2011 7:45 pm

@Ashley
Confirmed. The expression editor won't take an expression like
"red"="red"
It says "type mismatch, = does not work with 'integer' and 'string' (use & to build strings)"

@dcrew
You can use a private variable to combine picking across events to do an "or".
http://dl.dropbox.com/u/5426011/examples%208/or_example.capx
B
79
S
24
G
54
Posts: 4,743
Reputation: 40,749

Post » Thu Dec 29, 2011 8:08 pm

[QUOTE=R0J0hound] @Ashley
Confirmed. The expression editor won't take an expression like
"red"="red"
It says "type mismatch, = does not work with 'integer' and 'string' (use & to build strings)"

@dcrew
You can use a private variable to combine picking across events to do an "or".
http://dl.dropbox.com/u/5426011/examples%208/or_example.capx
[/QUOTE]

Does no one understand what I asked for? I don't want multiple events, for example: take your capx and the event "Is animation 'Red' Playing?" rather than having it seperate I want: "Is animation 'Red' or 'Blue' or 'Green' or 'Purple' Playing?" for reasons I do not feel the need to explain. I'm happy to wait till Tom and Ashley fix this dcrew2011-12-29 20:09:12
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Thu Dec 29, 2011 9:43 pm

[QUOTE=dcrew]Does no one understand what I asked for? I don't want multiple events, for example: take your capx and the event "Is animation 'Red' Playing?" rather than having it seperate I want: "Is animation 'Red' or 'Blue' or 'Green' or 'Purple' Playing?" for reasons I do not feel the need to explain.[/QUOTE]
I know you won't listen, because I tried to explain it two times. We did understand, but the simple fact is, "or" in a programming language does not work like "or" in a spoken language.
While you can say, "Is the apple's color 'green', or 'red', or 'orange'?", and everyone will understand you, for the logic of a programming language you have to phrase, "Is the apple's color 'green', or is the apple's color 'red', or is the apple's color 'orange'?", which is a tiny little difference for us humans, but a huge one for logical operators.

The first one will look to Construct like so: "Is the apple's color 'TRUE', or 'TRUE', or 'TRUE' "
Now 'or' returns true if any of the elements result to true. They all result to true, no matter what the real color's name is, because they are non-empty strings, so the result will always be 'TRUE'.
What you need is a way to get the boolean 'TRUE' only if the apple's color is either of the three color names and 'FALSE' in all other cases.

That's why the second one is so important. There you have three evaluations and every single one will only be true, if the apple's color matches that name. Let's say, the current color name is 'green', then the second one will look to Construct like so: " 'TRUE', or 'FALSE', or 'FALSE' "

That's important as soon as the real color of the apple does not match any of the three color names. Let's say, the color of the apple is 'purple'.

First one will still read as: "Is the apple's color 'TRUE', or 'TRUE', or 'TRUE'" That will result to 'TRUE', so the event will be executed, although the apple does not have the correct color.

Second one will read as: " 'FALSE', or 'FALSE', or 'FALSE' " That would result to 'FALSE', just as we expect it to be.

As soon as the type mismatch issue is corrected by Ashley, you still have to phrase it the right way.
Block.AnimationName = "Block1" | "Block3" | "Block13" | "Block14"
will still not work (as I explained above). It is phrased wrong.
Block.AnimationName = "Block1" | Block.AnimationName = "Block3" | Block.AnimationName = "Block13" | Block.AnimationName = "Block14"
is the only way to make it work as you want it to behave.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Dec 30, 2011 12:40 am

@tulamide

Sorry, I misunderstood. Now I understand, thanks! And I don't mind waiting
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Fri Dec 30, 2011 12:48 am

Well, I've fixed two bugs for the next build now thanks to this thread - numbers aren't accepted to animation parameters, and the = operator works properly for strings. So hopefully it will be a little smoother in the next release :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Fri Dec 30, 2011 1:00 am

Um even if they add a way to add multiple comparisons to or, that wont work with picking using the system compare. Also you have the possibility of triggering the action more than once.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

PreviousNext

Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest