Thorou
Thorou

Reputation: 3

variable not accessible after #If directive

var1 := "this works"

#If WinActive("")
d::d
#If

var2 := "this doesn't"

x::
    MsgBox, %var1%, %var2%
return

When the hotkey is triggered, it only displays var1, acting like var2 doesn't exist at all.
Why does this happen and what can I do to access var2 from the hotkey?
I can't move var2 up, since my actual code is split accross two files.

Upvotes: 0

Views: 132

Answers (1)

Relax
Relax

Reputation: 10543

You cannot define a variable between or after hotkeys or hotstrings. Hotkeys/Hotstrings terminate the automatic execution of code lines and the line

var2 := "this doesn't"

never becomes true because is never executed.

A variable has to be defined

  • in the auto-execute section (top of the script before the first return or hotkey),
  • or in a hotkey/hotstring,
  • or in a label (subroutine),
  • or in a function.

Upvotes: 2

Related Questions