Autohotkey 通过函数传递数组,然后循环

Autohotkey 通过函数传递数组,然后循环,autohotkey,Autohotkey,我正在编写一个循环imagesearch的函数,但我很难弄清楚如何使用数组允许的选项传递动态变量(例如,Array0检索数组中的记录总数,以及array%a_Index%,当与循环一起使用时,在列表中显示每个名称) 您在如何调用变量方面遇到了一些问题。实际上,您并没有使用“真实”数组,而是使用所谓的“伪数组”。您可以在文档中阅读它们 它们是AHK处理数组的老方法,我强烈建议您尝试在AHK中使用它们。如果您还没有-,您还应该将您的AHK版本更新为最新版本 我更改了脚本调用一些变量的方式,现在应该可

我正在编写一个循环imagesearch的函数,但我很难弄清楚如何使用数组允许的选项传递动态变量(例如,Array0检索数组中的记录总数,以及array%a_Index%,当与循环一起使用时,在列表中显示每个名称)


您在如何调用变量方面遇到了一些问题。实际上,您并没有使用“真实”数组,而是使用所谓的“伪数组”。您可以在文档中阅读它们

它们是AHK处理数组的老方法,我强烈建议您尝试在AHK中使用它们。如果您还没有-,您还应该将您的AHK版本更新为最新版本

我更改了脚本调用一些变量的方式,现在应该可以工作了,试试这个,注意我已经对我更改的行进行了注释:

arrowList = C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png
StringSplit, arrowArray, arrowList, |
buildList = C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png
StringSplit, buildArray, buildList, |

SearchArray("arrowArray", "buildArray")

SearchArray(ByRef x, ByRef y) 
{
    Loop, % %x%0 ; Changed this line
    {
        x2get := %x% A_Index ; Changed this line
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %x2get% ; Changed this line
        tooltip, searching for %x2get% , 0, 0
        If ErrorLevel = 0
        {
            Loop, % %y%0 ; Changed this line
            {
                y2get := % %y% A_Index ; Changed this line
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %y2get%  ; Changed this line
                tooltip, searching for %y2get% , 0, 0
                If ErrorLevel = 0
                {
                    MouseClick, Left, %imageX%, %imageY% ; Changed this line
                    Sleep 1000
                }
            }
        }
    }   
}
如果您对使用“真实”数组的解决方案的外观感兴趣,下面是一个例子。在尝试之前,请确保您正在运行最新版本的AHK,否则可能会失败

arrowList := "C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png"
arrowArray := StrSplit(arrowList, "|")
buildList := "C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png"
buildArray := StrSplit(buildList, "|")

SearchArray(arrowArray, buildArray)

SearchArray(firstArray, secondArray) {

    ; Iterate through the first array
    for outerIndex, outerValue in firstArray {
        ; outerIndex = Index of the current element; 1, 2, etc...
        ; outerValue = The value of the string at that index

        Tooltip, Searching for %outerValue%, 0, 0
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %outerValue%
        if (ErrorLevel = 0) {

            ; Iterate through the second array
            for innerIndex, innerValue in secondArray {
                ; innerIndex = Index of the current element; 1, 2, etc...
                ; innerValue = The value of the string at that index

                Tooltip, Searching for %innerValue%, 0, 0
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %innerValue%
                if (ErrorLevel = 0) {
                    MouseClick, Left, %imageX%, %imageY%
                    Sleep, 1000
                }
            }
        }
    }
}

您在如何调用变量方面遇到了一些问题。实际上,您并没有使用“真实”数组,而是使用所谓的“伪数组”。您可以在文档中阅读它们

它们是AHK处理数组的老方法,我强烈建议您尝试在AHK中使用它们。如果您还没有-,您还应该将您的AHK版本更新为最新版本

我更改了脚本调用一些变量的方式,现在应该可以工作了,试试这个,注意我已经对我更改的行进行了注释:

arrowList = C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png
StringSplit, arrowArray, arrowList, |
buildList = C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png
StringSplit, buildArray, buildList, |

SearchArray("arrowArray", "buildArray")

SearchArray(ByRef x, ByRef y) 
{
    Loop, % %x%0 ; Changed this line
    {
        x2get := %x% A_Index ; Changed this line
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %x2get% ; Changed this line
        tooltip, searching for %x2get% , 0, 0
        If ErrorLevel = 0
        {
            Loop, % %y%0 ; Changed this line
            {
                y2get := % %y% A_Index ; Changed this line
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %y2get%  ; Changed this line
                tooltip, searching for %y2get% , 0, 0
                If ErrorLevel = 0
                {
                    MouseClick, Left, %imageX%, %imageY% ; Changed this line
                    Sleep 1000
                }
            }
        }
    }   
}
如果您对使用“真实”数组的解决方案的外观感兴趣,下面是一个例子。在尝试之前,请确保您正在运行最新版本的AHK,否则可能会失败

arrowList := "C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png"
arrowArray := StrSplit(arrowList, "|")
buildList := "C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png"
buildArray := StrSplit(buildList, "|")

SearchArray(arrowArray, buildArray)

SearchArray(firstArray, secondArray) {

    ; Iterate through the first array
    for outerIndex, outerValue in firstArray {
        ; outerIndex = Index of the current element; 1, 2, etc...
        ; outerValue = The value of the string at that index

        Tooltip, Searching for %outerValue%, 0, 0
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %outerValue%
        if (ErrorLevel = 0) {

            ; Iterate through the second array
            for innerIndex, innerValue in secondArray {
                ; innerIndex = Index of the current element; 1, 2, etc...
                ; innerValue = The value of the string at that index

                Tooltip, Searching for %innerValue%, 0, 0
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %innerValue%
                if (ErrorLevel = 0) {
                    MouseClick, Left, %imageX%, %imageY%
                    Sleep, 1000
                }
            }
        }
    }
}

您在如何调用变量方面遇到了一些问题。实际上,您并没有使用“真实”数组,而是使用所谓的“伪数组”。您可以在文档中阅读它们

它们是AHK处理数组的老方法,我强烈建议您尝试在AHK中使用它们。如果您还没有-,您还应该将您的AHK版本更新为最新版本

我更改了脚本调用一些变量的方式,现在应该可以工作了,试试这个,注意我已经对我更改的行进行了注释:

arrowList = C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png
StringSplit, arrowArray, arrowList, |
buildList = C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png
StringSplit, buildArray, buildList, |

SearchArray("arrowArray", "buildArray")

SearchArray(ByRef x, ByRef y) 
{
    Loop, % %x%0 ; Changed this line
    {
        x2get := %x% A_Index ; Changed this line
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %x2get% ; Changed this line
        tooltip, searching for %x2get% , 0, 0
        If ErrorLevel = 0
        {
            Loop, % %y%0 ; Changed this line
            {
                y2get := % %y% A_Index ; Changed this line
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %y2get%  ; Changed this line
                tooltip, searching for %y2get% , 0, 0
                If ErrorLevel = 0
                {
                    MouseClick, Left, %imageX%, %imageY% ; Changed this line
                    Sleep 1000
                }
            }
        }
    }   
}
如果您对使用“真实”数组的解决方案的外观感兴趣,下面是一个例子。在尝试之前,请确保您正在运行最新版本的AHK,否则可能会失败

arrowList := "C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png"
arrowArray := StrSplit(arrowList, "|")
buildList := "C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png"
buildArray := StrSplit(buildList, "|")

SearchArray(arrowArray, buildArray)

SearchArray(firstArray, secondArray) {

    ; Iterate through the first array
    for outerIndex, outerValue in firstArray {
        ; outerIndex = Index of the current element; 1, 2, etc...
        ; outerValue = The value of the string at that index

        Tooltip, Searching for %outerValue%, 0, 0
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %outerValue%
        if (ErrorLevel = 0) {

            ; Iterate through the second array
            for innerIndex, innerValue in secondArray {
                ; innerIndex = Index of the current element; 1, 2, etc...
                ; innerValue = The value of the string at that index

                Tooltip, Searching for %innerValue%, 0, 0
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %innerValue%
                if (ErrorLevel = 0) {
                    MouseClick, Left, %imageX%, %imageY%
                    Sleep, 1000
                }
            }
        }
    }
}

您在如何调用变量方面遇到了一些问题。实际上,您并没有使用“真实”数组,而是使用所谓的“伪数组”。您可以在文档中阅读它们

它们是AHK处理数组的老方法,我强烈建议您尝试在AHK中使用它们。如果您还没有-,您还应该将您的AHK版本更新为最新版本

我更改了脚本调用一些变量的方式,现在应该可以工作了,试试这个,注意我已经对我更改的行进行了注释:

arrowList = C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png
StringSplit, arrowArray, arrowList, |
buildList = C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png
StringSplit, buildArray, buildList, |

SearchArray("arrowArray", "buildArray")

SearchArray(ByRef x, ByRef y) 
{
    Loop, % %x%0 ; Changed this line
    {
        x2get := %x% A_Index ; Changed this line
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %x2get% ; Changed this line
        tooltip, searching for %x2get% , 0, 0
        If ErrorLevel = 0
        {
            Loop, % %y%0 ; Changed this line
            {
                y2get := % %y% A_Index ; Changed this line
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %y2get%  ; Changed this line
                tooltip, searching for %y2get% , 0, 0
                If ErrorLevel = 0
                {
                    MouseClick, Left, %imageX%, %imageY% ; Changed this line
                    Sleep 1000
                }
            }
        }
    }   
}
如果您对使用“真实”数组的解决方案的外观感兴趣,下面是一个例子。在尝试之前,请确保您正在运行最新版本的AHK,否则可能会失败

arrowList := "C:\AHK\LeftArrow.png|C:\AHK\LeftArrow1.png|C:\AHK\GreenLeftArrow.png"
arrowArray := StrSplit(arrowList, "|")
buildList := "C:\AHK\build1.png|C:\AHK\build2.png|C:\AHK\build3.png|C:\AHK\build4.png|C:\AHK\build5.png"
buildArray := StrSplit(buildList, "|")

SearchArray(arrowArray, buildArray)

SearchArray(firstArray, secondArray) {

    ; Iterate through the first array
    for outerIndex, outerValue in firstArray {
        ; outerIndex = Index of the current element; 1, 2, etc...
        ; outerValue = The value of the string at that index

        Tooltip, Searching for %outerValue%, 0, 0
        ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %outerValue%
        if (ErrorLevel = 0) {

            ; Iterate through the second array
            for innerIndex, innerValue in secondArray {
                ; innerIndex = Index of the current element; 1, 2, etc...
                ; innerValue = The value of the string at that index

                Tooltip, Searching for %innerValue%, 0, 0
                ImageSearch, imageX, imageY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 %innerValue%
                if (ErrorLevel = 0) {
                    MouseClick, Left, %imageX%, %imageY%
                    Sleep, 1000
                }
            }
        }
    }
}
“真正的阵列”解决方案工作得很好,虽然我是最新的,但我需要升级到.02:)谢谢西多拉!“真正的阵列”解决方案工作得很好,虽然我是最新的,但我需要升级到.02:)谢谢西多拉!“真正的阵列”解决方案工作得很好,虽然我是最新的,但我需要升级到.02:)谢谢西多拉!“真正的阵列”解决方案工作得很好,虽然我是最新的,但我需要升级到.02:)谢谢西多拉!