Summary:
Code: Select all
(cond) && (action) ;valid in AHK v1/v2
(cond) ? (action) : 0 ;valid in AHK v1/v2
(cond) ? (action) ;works in AHK v1 (but not really valid), invalid in /v2
Explaining the magic. One thing you likely know, which is mentioned in the documentation, but which I'll mention anyway. Fundamentally, in short-circuit Boolean evaluation, things that can't affect the final outcome, aren't executed, so for
if a && b, if a is false, then a && b must be false, so we don't bother to evaluate b.
Code: Select all
;from this:
if a && b
MsgBox, 1
else
MsgBox, 0
;comes this (if a is true, then assign b, if b is true, then do action 1, else do action 2):
if a && (b:=1)
MsgBox, 1
else
MsgBox, 0
;comes this, which somehow works (do a, if a is true, do b):
(a) && (b)
;although that these work, perhaps isn't too surprising:
var := (a) && (b)
MsgBox, % var
MsgBox, % (a) && (b)