AutoHotKey投掷错误:尽管括号似乎正确

时间:2019-11-05 22:48:22

标签: compiler-errors autohotkey curly-braces unexpected-token

添加Else语句后,脚本将无法编译为括号不正确的内容。编译器说第67行是罪魁祸首,我不确定为什么。

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Pixel
SendMode Input
#SingleInstance Force
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1

^!6::
CoordMode, Pixel, Screen
CoordMode, ToolTip, Screen
CoordMode, Mouse, Screen

Click, 830, 393
Sleep 2000
Click, 678, 538
Sleep 500

Click, 840, 800
Sleep 2000
Click, 671, 974
Sleep 500


Click, 1775, 300
Sleep 2000
Click, 1643, 487
Sleep 2000

var = 0
Loop {
    ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *100 C:\Users\USER\Desktop\Folder\ImageAssets\storage4x4\image%var%.jpg

    If (ErrorLevel = 0) {
        If %var% = 0 {
            Click, %FoundX%, %FoundY%
            Sleep 50
            Click, %FoundX%, %FoundY%
            Sleep 100
            ToolTip, Refreshing Store..., %FoundX%, %FoundY%
        }

        Else {
            SoundPlay, C:\Users\USER\Desktop\Folder\SoundAssets\found.wav
            Click, %FoundX%, %FoundY%
            Sleep 50
            Click, %FoundX%, %FoundY%
            ToolTip, image%var%.jpg, %FoundX% + 10, %FoundY% + 10
            ErrorLevel := -1
            FoundX := ""
            FoundY := ""
            SearchAndPurchase()
        }
    }

    If ErrorLevel 
        ToolTip, Didn't find image%var%.jpg, 0, 25

    If var >= 10 
        var = 


     var += 1
}
Return

SearchAndPurchase(){
    Sleep 5000
    var = 0 
    Loop, 5 {
        var += 1
        Sleep 5000
        ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *100 C:\Users\USER\Desktop\Folder\ImageAssets\storage4x4\Storage4x4Store\image%var%.jpg

        If (ErrorLevel = 0) {
            SoundPlay, C:\Users\USER\Desktop\Folder\SoundAssets\chaching.wav
            Click, %FoundX%, %FoundY%
            ToolTip, $$$ image%var%.jpg $$$, %FoundX% + 10, %FoundY% + 10
            Sleep 50
            Click, %FoundX%, %FoundY%
            FoundX := ""
            FoundY := ""
        }
        If (ErrorLevel) 
            ToolTip, Couldn't purchase... 0, 75
        If (var >= 10) 
            var = 0
    }

    ToolTip, Leaving Store and refreshing market..., 0, 25
    Click, 678, 538
    Click, 678, 1043
    Click, 1643, 538
    Sleep 2000
    Click, 678, 538
    Click, 678, 1043
    Click, 1643, 538
    Sleep 2000
}


Esc:: ExitApp

我计算了所有括号,并且代码中每个方向都有7个。我还删除了所有括号,并重新添加了几次,以尝试发现错误,但是没有运气。这是怎么回事?

2 个答案:

答案 0 :(得分:1)

您有一个浮动的作业:

var = 在第63行

大括号是意外的,因为它希望您完成句子。

答案 1 :(得分:1)

万一其他人遇到类似问题,请检查您的if语句并将所有条件放在括号中。在此示例中,它在将所有if条件放在括号内后进行了修复(以及AnnoyinC的评论),然后工作了。