Jump to content

Switch / Select / case


Recommended Posts

ERROR: syntax error (illegal character)
        Case $Char_Mode = "
        ~~~~~~~~~~~~~~~~~~^
why??

the whole function...

;================================================
;Create a game in battlenet with dynamic waits & retries.
;Returns 0 if failed
;Returns 1 if success
;================================================
Func CreateGame($Char_Mode, $Run_GameName = "error", $Run_PasswordType = "error")
    If ($Run_GameName = "error") Or ($Run_PasswordType = "error") Then
        LogEvent (1, "$Char_Mode must be either ""Battle"" or ""Single"". Please read the manual and configure the bot.")
        Return 0
    EndIf
    Select
        Case $Char_Mode = "Battle"
            For $Retry = 1 To 5
                LogEvent (0, "Attempting to create the game " & $GameName & $RunCount & " This is attempt number " & $Retry)
                MouseClick("Left", 590, 462, 1, $MenuMouseSpeed)
                If ScreenWait("CreateButton", 5000) = 0 Then
                    MouseClick("Left", 712, 461, 1, $MenuMouseSpeed)
                    Sleep(2000)
                    ContinueLoop
                EndIf
                
                ;Send the Game Name
                If $Run_GameName = "Random" Then
                    For $N = 0 To Random(8, 10, 1)
                        $rand = Random(0, 1, 1)
                        Send(Chr(Mod(Random(1, 26, 1), ($rand * 16) + 10) + (($rand * 49) + 48))) ;Send an alphaneumeric random Digit
                    Next
                Else
                    Send($Run_GameName & $RunCount)
                EndIf
                
                Sleep(200)
                Send("{TAB}")
                
                ;Send the Password
                If $Run_PasswordType = "Random" Then
                    Send(Random(100, 999999, 1))
                ElseIf $Run_PasswordType = "Numbered" Then
                    Send($RunCount)
                EndIf
                
                MouseClick("Left", 676, 418, 1, $MenuMouseSpeed) ;Click create game
                If ScreenWait("GameJoin", 5000) = 0 Then
                    LogEvent (1, "Game create screen not detected after 5 seconds... will retry the game join.")
                    MouseClick("Left", 711, 461, 1, $MenuMouseSpeed)
                    ContinueLoop
                EndIf
                Local $Timeout = TimerInit()
                While ScreenCheck("GameJoin") = 1
                    If TimerDiff($Timeout) > 30000 Then
                        LogEvent (1, "Looks like we got stuck on the game create screen for over 30 seconds...")
                        Return 0
                    EndIf
                    Sleep(500)
                WEnd
                If ScreenCheck("Lobby") = 1 Then
                    LogEvent (1, "Failed to Join! Bnet needs to fix their damn servers!!! Lets just retry...")
                    ContinueLoop
                ElseIf ScreenCheck("GUIBar") = 1 Then
                    LogEvent (0, "Successfully joined the game after " & Round((TimerDiff($Timeout) / 1000), 2) & " seconds.")
                    Return 1
                Else
                    LogEvent (1, "Hmm, looks like we got lost somewhere while attempting to create a game...")
                    Return 0
                EndIf
            Next
            LogEvent (1, "Failed to create a game after 5 retries.")
            Return 0
        Case $Char_Mode = "Single"
            MouseClick("Left", 394, 310, 1, $MenuMouseSpeed) ;Click the Single Player button on the main menu.
            If ScreenWait("CharacterSelect", 10000) = 0 Then Return 0
            MouseClick("Left", 173 + (IsInt($CharSlot / 2) * 277), 130 + (93 * (($CharSlot / 2) - 1)), 1, $MenuMouseSpeed) ;Click the character at the appropriate slot
            MouseClick("Left", 690, 556, 1, $MenuMouseSpeed) ;Click OK
            If ScreenWait("GameJoin", 5000) = 0 Then
                LogEvent (1, "Game create screen not detected after 5 seconds... will retry the game join.")
                MouseClick("Left", 711, 461, 1, $MenuMouseSpeed)
                Return 0
            EndIf
            Local $Timeout = TimerInit()
            While ScreenCheck("GameJoin") = 1
                If TimerDiff($Timeout) > 30000 Then
                    LogEvent (1, "Looks like we got stuck on the game create screen for over 30 seconds...")
                    Return 0
                EndIf
                Sleep(500)
            WEnd
            If ScreenCheck("GUIBar") = 1 Then
                LogEvent (0, "Successfully joined the game after " & Round((TimerDiff($Timeout) / 1000), 2) & " seconds.")
                Return 1
            Else
                LogEvent (1, "Hmm, looks like we got lost somewhere while attempting to create a game...")
                Return 0
            EndIf
    EndSelect
    
EndFunc   ;==>CreateGame

Tried both select & switch. Neither works. Do i really have improper synatx? The only other solution i can think of is either using a very bigass if/elseif, or splitting this into two functions.

Link to comment
Share on other sites

  • Developers

ERROR: syntax error (illegal character)
        Case $Char_Mode = "
        ~~~~~~~~~~~~~~~~~~^
why??

Tried both select & switch. Neither works. Do i really have improper synatx? The only other solution i can think of is either using a very bigass if/elseif, or splitting this into two functions.

Have you tried your posted code ? gives a lot of errors except the one you posted ... so its difficult to help you .. :) Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Have you tried your posted code ? gives a lot of errors except the one you posted ... so its difficult to help you .. :)

Yes I'm sure it would cause a lot of errors if you tried to run it by itself since this is part of a very big script with multiple includes. After doing some testing, it seems that Select does not handle strings for some reason. I wonder if there is any way around this like by storing the string to compare in another variable... any suggestions? I would think this would be able to use strings.
Link to comment
Share on other sites

Yes I'm sure it would cause a lot of errors if you tried to run it by itself since this is part of a very big script with multiple includes. After doing some testing, it seems that Select does not handle strings for some reason. I wonder if there is any way around this like by storing the string to compare in another variable... any suggestions? I would think this would be able to use strings.

This code is OK:

Func CreateGame($Char_Mode, $Run_GameName = "error", $Run_PasswordType = "error")
    Select
        Case $Char_Mode = "Battle"
        Case $Char_Mode = "Single"
    EndSelect
EndFunc

So problem is inside your code in Case and not with Case statement.

Try eliminating method.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...