1

添加 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 个。我还删除了所有括号并重新添加了几次以尝试发现错误,但没有运气。这里发生了什么?

4

2 回答 2

1

如果其他人看到类似的问题,请检查您的 if 语句并将所有条件放入括号中。在这个例子中,它在将所有 if 条件放在括号内之后修复(连同 AnnoyinC 的评论)后工作。

于 2019-11-06T01:07:06.350 回答
1

你有一个浮动分配:

var = 在第 63 行

大括号是出乎意料的,因为它希望你完成你的句子。

于 2019-11-05T22:52:39.730 回答