Blitz3D+ Command Reference

expression1 Or expression2

Parameters

expression1 - the value or condition on the left

expression2 - the value or condition on the right

Description

Combines two values bit by bit, keeping every bit that is set in either one.

Like And, Or does double duty. As a condition joiner it gives you "either of these": If KeyDown(57) Or KeyDown(28) Then Fire. Comparisons produce 1 or 0, so the bitwise result reads exactly as you would hope. Or has the lowest precedence in the language along with And and Xor, so the comparisons on both sides resolve before it runs.

As a bit operation it is how you switch flags on. flags = flags Or 4 sets bit 2 and leaves everything else alone, the standard partner to testing with And and clearing with Xor. Packing several values into one integer uses Or to merge the pieces after shifting them into place.

The same caution applies: Or is bitwise rather than logical, and both sides are always evaluated - there is no short-circuit, so the right-hand side runs even when the left is already true.

See also: And, Not, Xor, If, Shl.

Example

; Or Example
; ----------

; Or is true when EITHER side is true (or both) - for Ifs where any
; one condition is enough. On plain integers it also works bitwise,
; which is how option flags get combined.

shield=0
potion=1

; Logical use: one true side is enough
If shield Or potion Then
    Print "You have some protection (shield="+shield+", potion="+potion+")"
Else
    Print "Completely defenceless!"
EndIf

Print ""

; Bitwise use: a bit set in EITHER value appears in the result
a=%1100
b=%1010
Print "a      = "+Bin$(a)+" ("+a+")"
Print "b      = "+Bin$(b)+" ("+b+")"
Print "a Or b = "+Bin$(a Or b)+" ("+(a Or b)+")"

Print ""

; Combining single-bit flag values into one integer
Print "Flags 1, 2 and 8 combined: 1 Or 2 Or 8 = "+(1 Or 2 Or 8)

Print ""
Print "Press any key to close the example"
WaitKey

End

Index