Sign in to follow this  
Followers 0
Hidden

Using Else more than once

6 posts in this topic

#1 ·  Posted (edited)

Hey guys. I'm having some trouble using the Else statement more than once, and being the noob that I am at this, I need some help.

Ok, so here's the story.

I want a constant loop, which I have set, and I'm using pixelsearch.

Now heres the thing. I have the 2 pixel searches set, but I cannot set a third. It keeps telling me that there are too many Else statements for the If statement.

Thing is... I don't need another If statement in the program.

I used to program a bit in VB back in the day, and never used to have problems with ElseIf statements...

Here's my code:

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{END}", "Terminate")
Global $Paused
Send("{PAUSE}")

Dim $SearchResult
Dim $SearchClose
While 78945 = 78945

    $SearchClose = PixelSearch(400, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose[0], $SearchClose[1])
Sleep(3500)

Else

    $SearchResult = PixelSearch(200, 268, 706, 600, 0x2A2A1A, 1, 2) 


        MouseMove($SearchResult[0], $SearchResult[1]);search
    MouseClick("left", $SearchResult[0], $SearchResult[1]);pick
    Sleep(6000)


Endif



WEnd



Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc
Func Terminate()
    Exit 0
EndFunc

And here's what I want it to be:

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{END}", "Terminate")
Global $Paused
Send("{PAUSE}")

Dim $SearchResult
Dim $SearchClose
While 78945 = 78945

    $SearchClose = PixelSearch(400, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose[0], $SearchClose[1])
Sleep(3500)

Else

    $SearchResult = PixelSearch(200, 268, 706, 600, 0x2A2A1A, 1, 2) 


        MouseMove($SearchResult[0], $SearchResult[1]);search
    MouseClick("left", $SearchResult[0], $SearchResult[1]);pick
    Sleep(6000)

Else

MouseClick("left", 650, 400)

Endif



WEnd



Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc
Func Terminate()
    Exit 0
EndFunc

Also guys, if you could please explain to me how to achieve this, it would be great. I'd like to make the searches a bit more complicated. So it searches close by rather than the whole screen. If theres nothing in immediate vecinity, then search a little bit further, and so on until it reaches full screen. I want to do this because it sometimes ignores things that are close by and it just goes for what ever is furthest to the left.

Edited by Hidden

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I see you've used 2 Else statements in one If..EndIf statement. You can only have one Else statement inside it. For example, this is incorrect:

If 1+1 = 2 Then
    Msgbox(0,"","1+1=2")
Else
    Msgbox(0,"","1+1 is not equal to 2")
Else
    Msgbox(0,"","Why are there 2 Else statements?")
EndIfoÝ÷ Øýz-{¶¬º·°«r¢ìÛhv(#eW½è­ºhÊzg¦mêí«r¢ç¯zk¥¶*exIlzËZµéÛ"*.«Þém^!ñ't÷öÁ1jjey«­¢+Ù%ĬÄôÈQ¡¸(5ͽà À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½ÐìĬÄôÈÅÕ½Ðì¤)±Í(5ͽà À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½ÐìĬĽ̹½ÐÅհѼÈÅÕ½Ðì¤(%ĬÈôÈQ¡¸(5ͽà À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí=­ä°å½ÔÌäíɽµÁ±Ñ¥¥½ÐÅÕ½Ðì¤(±Í(5ͽà À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½ÐíбÍÐå½ÔÌäíɹ½ÐÑ¡ÐÍÑÕÁ¥ÅÕ½Ðì¤(¹%)¹%

Hope you can study of off that to understand this better. As for your pixelsearch problem, if a color you want to pick up is similar to another color you want to pick up, try playing around with the Shade-Variation parameter. And if your "object" you want to pick up is 15+ pixels by 15+ pixels, jack-up the Step parameter (important!).

PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )

Good Luck,

Kurt

EDIT: Look-up PixelSearch in the helpfile for more information (hotkey F1 in SciTe for quick-access)

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Kurt, problem is that if I use 2 if statements, it conflicts with the Wend.

And Larry, if I use ElseIf, it still gives me too many Else statements under 1 If.

The thing is that, the If doesn't really change...

The problem put quickly is supposed to be as so:

If you don't find the pixel in area1

Search it in area2

If you don't find the pixel in area2

Search it in area3

If you don't find the pixel in area3

Search it in area4.

Area 1 = Middle of screen

Area 2 = A bit more than middle

Area 3 = A bit more than previous

Area 4 = A bit more than previous.

But if you find it in area 1, don't go ahead and click the one in area 2...

If I were able to use Else statements more than once, it would look like this:

$SearchClose = PixelSearch(400, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose[0], $SearchClose[1])
Sleep(3500)

Else

$SearchClose1 = PixelSearch(350 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose1[0], $SearchClose1[1])
Sleep(3500)

Else

$SearchClose2 = PixelSearch(300, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose2[0], $SearchClose2[1])
Sleep(3500)

Else

$SearchClose3 = PixelSearch(250, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose3[0], $SearchClose3[1])
Sleep(3500)

Else

$SearchClose4 = PixelSearch(200, 350, 490, 470, 0x2A2A1A, 1, 2); Search close by

if Not @error then


MouseClick("left", $SearchClose4[0], $SearchClose4[1])
Sleep(3500)

Endif

Now the question is, how can I achieve that, in AutoIt programming?

Edited by Hidden

Share this post


Link to post
Share on other sites

Well, here's a little something to think about:

$timer = TimerInit
While 1
    If TimerDiff($timer) > 7500 Then
        $PixelSearch1 = PixelSearch(400, 350, 490, 470, 0x2A2A1A, 1, 2)
        If Not @error Then ;If it succeeds
            ;YAY pixelsearch succeeded
        Else
            $PixelSearch2 = PixelSearch(200, 268, 706, 600, 0x2A2A1A, 1, 2)
            If Not @error Then ;If it succeeds
                ;YAY pixelsearch succeeded
            Else
                $PixelSearch3 = PixelSearch(...)
                If Not @error Then ;If it succeeds
                    ;YAY pixelsearch succeeded
                Else
                    ;NO PIXELSEARCH SUCCEEDED
                EndIf
            EndIf
        EndIf
        $timer = 0
        $timer = TimerInit()
    EndIf
WEnd

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Well, here's a little something to think about:

$timer = TimerInit
While 1
    If TimerDiff($timer) > 7500 Then
        $PixelSearch1 = PixelSearch(400, 350, 490, 470, 0x2A2A1A, 1, 2)
        If Not @error Then ;If it succeeds
            ;YAY pixelsearch succeeded
        Else
            $PixelSearch2 = PixelSearch(200, 268, 706, 600, 0x2A2A1A, 1, 2)
            If Not @error Then ;If it succeeds
                ;YAY pixelsearch succeeded
            Else
                $PixelSearch3 = PixelSearch(...)
                If Not @error Then ;If it succeeds
                    ;YAY pixelsearch succeeded
                Else
                    ;NO PIXELSEARCH SUCCEEDED
                EndIf
            EndIf
        EndIf
        $timer = 0
        $timer = TimerInit()
    EndIf
WEnd

Kurt

Well what do you know? It worked. Thanks a lot Kurt.

I think I was putting the If / Else statements in the wrong places.

Thanks :whistle:

Share this post


Link to post
Share on other sites

And Larry, if I use ElseIf, it still gives me too many Else statements under 1 If.

$number = Random(1, 4, 1)

If $number = 1 Then
    MsgBox(64, $number, "You got one.")

ElseIf $number = 2 Then
    MsgBox(64, $number, "You got two.")

Else
    MsgBox(64, $number, "You got three or four.")

EndIf

Share this post


Link to post
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
Sign in to follow this  
Followers 0