When I declare a global variable after #ifwinactive, an error message pop up showing that the variable is not declared.
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.
On the top of the script I have these environment settings:
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2
Then I have many window-specific hotkeys:
#ifwinactive ahk_exe Explorer.EXE
;some hotkeys
#ifwinactive ahk_exe WINWORD.EXE
;some extra hotkeys
;etc.
At the bottom, I try to declare a global variable and this is where the error occurs:
#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