UnrealScript XOR XAND

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

UnrealScript XOR XAND

Post by 'Zac » Fri Oct 19, 2018 12:42 am

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: 1699
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: UnrealScript XOR XAND

Post by Barbie » Fri Oct 19, 2018 2:23 am

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.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
'Zac
Experienced
Posts: 102
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: UnrealScript XOR XAND

Post by 'Zac » Sat Oct 20, 2018 2:55 am

Thanks for the clearing up! and the links!
Prophunt for UT99!!!
Image
Github

Higor
Godlike
Posts: 1765
Joined: Sun Mar 04, 2012 6:47 pm

Re: UnrealScript XOR XAND

Post by Higor » Sat Oct 20, 2018 3:14 am

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 )
ImageImage
Image unreal://23.111.157.138:7777
Image unreal://46.228.199.205:7788