Talk:Operator Reference
There are no discussions on this page.
this does not sound to be worded correctly to me. am i thinking about that too hard?
- "The OR operator (||) will be true if one of the expressions to its left and right are true, and will short-circuit if the right expression is true (it will not evaluate the left expression at all)."
- and will short-circuit if the right expression is true (it will not evaluate the left expression at all).
- (it will not evaluate the left expression at all)
- and will short-circuit if the right expression is true (it will not evaluate the left expression at all).
Function X() Debug.Notification('x was evaluated') EndFunction Function Y() Debug.Notification('y was evaulated') EndFunction
If(X() || Y()) EndIf
that last bit suggests we would never see 'x was evaluated'. --Darkconsole (talk) 2016-08-25T16:26:29 (EDT)
- You maybe misunderstanding it. The OR operator will short-circuit if the left expression is true. As in, it doesn't check the right expression if that's the case. If the left is false, it checks if the right is true. For a long chain of OR operators, it checks all of the right expressions when the first left expression is false, and short-circuits on the first right expression found to be true.
- Some easy example.. say your character has 10mm Ammo. You want to do things if it has 3 'or' 5 bullets.
Function Foo()
Actor Player = Game.GetPlayer()
If Player.GetItemCount(10mmAmmo) == 3 || Player.GetItemCount(10mmAmmo) == 5
; if the player has 3 bullets OR 5 bullets, this code is processed.
EndFunction
From my understanding, the OR operator is a simple, yet potentially long-winded method of taking into account for things that may arise incase the desired expression is not met for some reason. It's like another way around an army of elseif statements, but you don't want TOO many OR expressions either. I hope I cleared that up.
--Twilight Sky (talk) 2016-08-25T18:40:57 (EDT)