1

Script won't compile do to the brackets being incorrect after adding the Else statement. Compiler says that line 67 is the culprit and I'm not sure why.

#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

I counted all the brackets and there are 7 of each direction in the code. I also deleted all brackets and re-added them a couple of times to try and catch mistake but with no luck. What's going on here?

Efie
  • 1,430
  • 2
  • 14
  • 34

2 Answers2

1

You have a floating assignment:

var = at line 63

The brace is unexpected because it expects you to finish your sentence.

AnnoyinC
  • 426
  • 4
  • 17
  • I fixed that but I'm still getting the same error unfortunately – Efie Nov 05 '19 at 23:01
  • When I compile your code, I get: >"C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in "C:\Users\Robert\DataFiles\_9 Programs\_Programming\AHK\Someonesprogram.ahk" Successfully compiled: >Exit code: 0 Time: 5.602... But then again, maybe my platform can't be trusted see: https://stackoverflow.com/questions/58738870/lbutton-hotkey-seems-to-prevent-send-lbutton?noredirect=1#comment103786202_58738870. I see, after compiling, you get the message.. Ignore my message. – Robert Ilbrink Nov 07 '19 at 16:32
1

In case anyone else see's this with a similar issue, check your if statements and put all of the conditions into parentheses. In this example, it worked after fixing (along with AnnoyinC's comment) after putting all of the if conditions inside parentheses.

Efie
  • 1,430
  • 2
  • 14
  • 34
  • Generally, as you mentioned, it's good practice to always use parenthesis for if-statement expressions (except for single true/false bool variables). In your specific case, though, what was happening was that it was checking if contents of "var" were equal to "0 {", so there was really no start brace as it was consumed as part of the expression. – EJE Nov 12 '19 at 13:10