Jump to content

I vs. II


Recommended Posts

No, those are not Roman numerals. It's the types of OR. What is the difference between them? Does the difference make a difference in a tp2? (race = 3 | race = 7) vs. (race = 3 || race = 7)?

Link to comment

|| is a logical operator and the better representation of how we use the word "or" in everyday language.

| is a bitwise operator that determines a result by evaluating two bit strings bit-by-bit.  For more information, see here.

Here are some examples to compare the behaviour.

0 || 0 is 0
0 | 0 is 0

1 || 0 is 1
1 | 0 is 1

2 || 0 is 1
2 | 0 is 2

5 || 12 is 1
5 | 12 is 13

The logical operator || will only ever return 0 or 1, while the bitwise operator | can return other numbers.

WeiDU treats the condition on an IF statement as true when it evaluates to any number other than 0, so PATCH_IF (x || y) would evaluate exactly same as PATCH_IF (x | y).  However, I would encourage using || for clarity if you are intending a logical comparison.  || is a synonym for OR, so you could also use OR.

Similarly, I'd suggest using the logical operator && (also known as AND) over the bitwise operator & within conditions.

Here are some examples to compare those two:

0 && 0 is 0
0 & 0 is 0

1 && 0 is 0
1 & 0 is 0

1 && 1 is 1
1 & 1 is 1

2 && 0 is 0
2 & 0 is 0

2 && 1 is 1
2 & 1 is 0

2 && 2 is 1
2 & 2 is 2

5 && 12 is 1
5 & 12 is 4

The behaviour of the bitwise operator & does not always match our usage of the word "and" in everyday language, demonstrated by 2 & 1 equalling 0.

The bitwise operators are best reserved for dealing with values that are stored bitwise, like usability flags within .itm files.

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...