Search code examples
compiler-errorsautohotkeycurly-braces

AutoHotkey choking on same-line curly brace for compound if statements


I have a problem where AutoHotkey tells me there is a missing { in front of an 'else' where I think my Code is perfectly fine. (It worked up until I changed the window-related if's from Pidgin to qutIM)

^!p::
   IfWinExist ahk_class QWidget, ,qutIM {  ;if there is a qutIM-window other than the buddy-list...
      IfWinNotActive ahk_class QWidget, , qutIM {  ;ans it is not active...
         WinActivate
      } else {  ;the closing bracket in front of the else here puts AHK off...
         WinMinimize
      } 
   } else {  ;do some stuff with the buddy-list
      ; [...]
   } 
return

I fear I'm overlooking something stupid, but I cannot seem to get this working.


Solution

  • If I am not mistaken, the One True Brace style is usable only with pure If statements, not with compounds like IfWinExist.

    From the documentation for if-expressions:

    The One True Brace (OTB) style may optionally be used with if-statements that are expressions (but not traditional if-statements).

    Ie. you have to use WinExist() form, not IfWinExist.