0

Please help check my Autohotkey(1.1.13.01) script:

#!r:: Reload
Sleep 1000
MsgBox, 4,, The script could not be reloaded. Open it for editing?
IfMsgBox, Yes, Edit
return

global gg := 10

#!t:: MsgBox % "gg= " . gg

myMsgBox(text)
{
     MsgBox % "mynum:" . text
}


#!y:: myMsgBox(%gg%) # gg does not carry 10 into myMsgBox

No matter Alt+Win+t or Alt+Win+q does not show variable expansion. I hope to see gg=10 in MsgBox but I only see gg=.

enter image description here

2

Global variables are to be defined in the auto-execute section:

global gg := 10

#!r:: Reload
Sleep 1000
MsgBox, 4,, The script could not be reloaded. Open it for editing?
IfMsgBox, Yes, Edit
return

#!t:: MsgBox % "gg=" . gg

#!y:: myMsgBox(gg)

myMsgBox(text){
MsgBox % "mynum:" . text
}
2
  • OK. Search the manual for auto-execute and got the idea. – Jimm Chen Jan 4 '15 at 14:12
  • One more question: If I #Include customize.ahk after global gg := 10 and #!r:: ... return, is it still possible to override gg's value in customize.ahk ? – Jimm Chen Jan 4 '15 at 14:26
2

You should also add the Reload command on a new line otherwise the lines below it will not be executed.

#!r:: ; new line here 
Reload
Sleep 1000
; ... rest of your script

To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line return. See http://ahkscript.org/docs/Tutorial.htm#Launch

3
  • I'm afraid you are not talking right, and not talking related to my question. – Jimm Chen Jan 10 '15 at 15:30
  • In your script the lines below your reload hotkey #!r (the lines with sleep 1000, MsgBox etc) will never be executed. I assume you meant to make #!r a multiline hotkey? If so you need to add a new line - read the documentation I linked to. I said ALSO because the location of your variable definition isn't the only mistake in the script if you want to have a multiline hotkey. – lintalist Jan 10 '15 at 18:08
  • Thank you. You're right. I now have moved Reload to its own line, in my production script. To keep context in this superuser page, I'll Keep my original code as is. – Jimm Chen Jan 11 '15 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.