Reputation: 51
(Very new to AHK, so sorry if this sounds very stupid/trivial)
I have a small AHK script (see below) with a variable called var
. I would like to call and modify this variable from within multiple hotkeys. However, even when trying to "yield" its value (with the F8
hotkey) the value doesn't get printed. How can I go about with this?
#SingleInstance, force
+Escape::ExitApp
!r::Reload
!p::Suspend
var := 42
F8::
MsgBox % "Var value is " . var . "."
Return
;F12::
;blabla not relevant yet
Upvotes: 0
Views: 185
Reputation: 6489
Your variable declaration is unreachable code.
The code execution stops when the first hotkey label is encountered. This is called the Auto-execute Section.
Move your hotkey definition to be at the very bottom.
(All hotkeys defined by hotkey labels always get created regardless of being in the auto-execute section or not)
And as a bonus, the concatenation operator .
is redundant, you don't need to use it, you can just leave it out.
(Unless you prefer to use it, of course)
Upvotes: 1