UnrealScript XOR XAND

Discussions about Coding and Scripting
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

UnrealScript XOR XAND

Post by 'Zac »

Hello, in some vanilla UT code, I see return statements that look like this:

Code: Select all

....
return Foo & Bar
or

Code: Select all

....
return Foo | Bar
I understand the usage in an if statement, meaning that

Code: Select all

Foo | Bar
is true if only one is false and one is true (Is this still correct UScript? I never use these one liners )

So my Question is, does....

Code: Select all

....
return Foo & Bar
// returns true if both are true? false if not?
or

Code: Select all

....
return Foo | Bar
// return true if one is false and one is true?
// or return the true value?
It's just always stuck with me since seeing this syntax, and I never see it anywhere else. Discuss below
Prophunt for UT99!!!
Image
Github
User avatar
Barbie
Godlike
Posts: 2911
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: UnrealScript XOR XAND

Post by Barbie »

A single "&" respective "|" means a bitwise AND respective OR, the double ones mean logical AND and OR.
Example:

Code: Select all

var byte a, b;

a = 3; // in dual notation 0000.0011
b = 5; // in dual notation 0000.0101

return a & b; // will return 0000.0001
See also If used in double variant (logical), just imagine some braces around the expression:

Code: Select all

var bool a, b;

a = true;
b = false;
return a && b; //same as return (a && b)  same as return FALSE;
'Zac wrote:I understand the usage in an if statement, meaning that

Code: Select all

Foo | Bar
is true if only one is false and one is true
Hmm, if you have meant

Code: Select all

Foo || Bar
then the expression is TRUE if one of the members is TRUE.
"If Origin not in center it be not in center." --Buggie
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: UnrealScript XOR XAND

Post by 'Zac »

Thanks for the clearing up! and the links!
Prophunt for UT99!!!
Image
Github
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: UnrealScript XOR XAND

Post by Higor »

In UnrealScript | and & are used as bitwise operators for integer types, and both RHS and LHS (right hand side, left hand side) are tested.

When it comes to || and &&, these are boolean operators with a 'skip' qualifier, LHS is checked first and depending on the result RHS may or may not be checked.

In other low level languages | and & may be used for many other types, and & may not yield the same results as &&, just as using & may crash your program.


==
Btw, in the case of booleans Exclusive-OR can be evaluated using !=

Code: Select all

if ( bool1 != bool2 )