Global variable does not have global scope

前端 未结 4 2041
予麋鹿
予麋鹿 2021-02-13 04:42
supposedlyGlobalVariable := \"blah\"

ARoutine()
{
   localVariable := \"asdf\"
   MsgBox, The global variable value is %supposedlyGlobalVariable%.  The local variable v         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-13 05:15

    This makes things easier:

    https://www.autohotkey.com/docs/Functions.htm#SuperGlobal

    Super-global variables [v1.1.05+]: If a global declaration appears outside of any function, it takes effect for all functions by default (excluding force-local functions). This avoids the need to redeclare the variable in each function. However, if a function parameter or local variable with the same name is declared, it takes precedence over the global variable. Variables created by the class keyword are also super-global.

    Just declare your variable as global in the main script:

    global supposedlyGlobalVariable := "blah"
    

提交回复
热议问题