Arrays 自动热键-声明全局数组不起作用

Arrays 自动热键-声明全局数组不起作用,arrays,insert,global,autohotkey,Arrays,Insert,Global,Autohotkey,似乎myList.Insert()在这里不起作用,因为脚本找不到数组,因此myList2为空。但是为什么呢?我以为我把阵列做成了全球性的 ; Give user the opportunity to choose his own hotkey Gui, Add, Hotkey, x21 y234 w240 h30 vPanicKey gRunPanicKey,^F12 global myList := ["foo"] RunPanicKey: if(PanicKey != "") {

似乎
myList.Insert()
在这里不起作用,因为脚本找不到数组,因此
myList2
为空。但是为什么呢?我以为我把阵列做成了全球性的

; Give user the opportunity to choose his own hotkey
Gui, Add, Hotkey, x21 y234 w240 h30 vPanicKey gRunPanicKey,^F12

global myList := ["foo"]

RunPanicKey:
    if(PanicKey != "") { ; Make sure the hotkey chosen by the user isn't empty.
        myList.Insert("bar") ; Insert new string into the array.
        myList2 := myList[2] ; Get 2nd index value and store it in myList2
        MsgBox,0,My Array, The 2nd value of myList is: %myList2%
    }
return

从您的评论中可以看出,问题不在
global
关键字中(您实际上根本不需要该关键字)。程序不工作的原因是
return
语句。脚本中第一次返回后的所有内容不会在脚本启动时自动执行。有关详细信息,请参阅。因此,只需在文件的最开始移动变量初始化。

afaik,在AHK中,您不需要将变量声明为全局变量,除非在函数中。因此,我不理解您的问题。我运行了你的程序(添加了
guishow
)。每次我输入一个键时,msgbox都会正确地显示
第二个值是bar
,因为这是分配给我的。我使用的是自动热键1.1.22.02,它对我不起作用。它只是说
我的列表的第二个值是:
。你应该发布完整的源代码,然后谢谢你,我真的不知道*
GuiClose:
    ExitApp
return

global myList := ["foo"]