title: Autohotkey: how to declare global variable after #ifwinactive
body: <p>When I declare a global variable after #ifwinactive, an error message pop up showing that the variable is not declared. </p>
  
  <p>I have a long script where there are many #ifwinactive ahk_exe xxx. Below those codes, I want to declare a global variable. But that doesn't work. Whenever I run the script, it warns me the global variable is not declared. Here's a brief of my script.</p>
  
  <p>On the top of the script I have these environment settings:</p>
  
  <pre><code>#NoEnv  
  #Warn  
  SendMode Input 
  SetWorkingDir %A_ScriptDir%
  SetTitleMatchMode, 2
  </code></pre>
  
  <p>Then I have many window-specific hotkeys:</p>
  
  <pre><code>#ifwinactive ahk_exe Explorer.EXE
  ;some hotkeys
  #ifwinactive ahk_exe WINWORD.EXE
  ;some extra hotkeys
  ;etc.
  </code></pre>
  
  <p>At the bottom, I try to declare a global variable and this is where the error occurs:</p>
  
  <pre><code>#ifwinactive
  a := 1
  ^p::
      if (a != 1){
          a := 1
      } else {
          a := 0
      }
  return 
  
  #if winactive("- YouTube -") and a != 1
      p::msgbox,Yes
  #if a = 1 and winactive("- YouTube -")
      p::msgbox,no
  #if
  </code></pre>