AHK 中的关联数组没有正确地将信息传递给方法
Associative Arrays in AHK not passing information to methods properly
我在将对象(以 关联数组 的形式)传递到单击像素位置的方法时遇到问题。该信息应该能够使用格式 value = arrayName[Key]
调用
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode Mouse Screen
;This Area is for defining any object nessesary to interact with the game
;
;
BACKPACK_28 := {UPPER_BOUND: 964, LOWER_BOUND: 995, LEFT_BOUND: 1569, RIGHT_BOUND: 1600, MENU_KEY: "esc"}
;
;
;Ends Game Object section
^l::
select(BACKPACK_28, true)
return
select(balls, switchMenus){
if(switchMenus==true){
SendInput {object[MENU_KEY]}
}
Random, y , balls[LOWER_BOUND], balls[UPPER_BOUND]
Random, x , balls[LEFT_BOUND], balls[RIGHT_BOUND]
Click, x, y
}
用引号初始化你的数组,像这样:
BACKPACK_28 := {"UPPER_BOUND": 964, ...}
否则,AHK 会将 UPPER_BOUND
视为单独的变量。
关于 Random, y , balls[LOWER_BOUND]
:请参阅有关 Random
的文档:
[Param] Min: The smallest number that can be generated, which can be negative, floating point, or an expression.
如果允许您在此处声明一个变量名称,它不会说数字。
使用%
s获取变量的值:
两者都
low := balls["LOWER_BOUND"]
up := balls["UPPER_BOUND"]
Random, y, %low%, %up%
或
Random, y, % balls["LOWER_BOUND"], % balls["UPPER_BOUND"]
我在将对象(以 关联数组 的形式)传递到单击像素位置的方法时遇到问题。该信息应该能够使用格式 value = arrayName[Key]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode Mouse Screen
;This Area is for defining any object nessesary to interact with the game
;
;
BACKPACK_28 := {UPPER_BOUND: 964, LOWER_BOUND: 995, LEFT_BOUND: 1569, RIGHT_BOUND: 1600, MENU_KEY: "esc"}
;
;
;Ends Game Object section
^l::
select(BACKPACK_28, true)
return
select(balls, switchMenus){
if(switchMenus==true){
SendInput {object[MENU_KEY]}
}
Random, y , balls[LOWER_BOUND], balls[UPPER_BOUND]
Random, x , balls[LEFT_BOUND], balls[RIGHT_BOUND]
Click, x, y
}
用引号初始化你的数组,像这样:
BACKPACK_28 := {"UPPER_BOUND": 964, ...}
否则,AHK 会将 UPPER_BOUND
视为单独的变量。
关于 Random, y , balls[LOWER_BOUND]
:请参阅有关 Random
的文档:
[Param] Min: The smallest number that can be generated, which can be negative, floating point, or an expression.
如果允许您在此处声明一个变量名称,它不会说数字。
使用%
s获取变量的值:
两者都
low := balls["LOWER_BOUND"]
up := balls["UPPER_BOUND"]
Random, y, %low%, %up%
或
Random, y, % balls["LOWER_BOUND"], % balls["UPPER_BOUND"]