How to "Alternate" between different actions inside a Loop.

Ask gaming related questions (AHK v1.1 and older)
superalfajor
Posts: 1
Joined: 06 Oct 2022, 12:20

How to "Alternate" between different actions inside a Loop.

Post by superalfajor » 06 Oct 2022, 12:29

Hi, I'm pretty new to this so I'm sure there's a lot to optimize here.

This is what i actually have:

Code: Select all

F7::
	Toggle :=false
	Loop
	{
        CoordMode, Pixel, Screen
        Coordmode, Mouse, Screen
        LoopCount = 1
		PixelSearch, pX, pY, 174, 189, 1630, 900, 0x000FF, 0, fast
        LoopCount := A_Index
        If ErrorLevel
        {
        }
        else
        {
          MouseClick, ,%px%, %py%
          Sleep 1500
        }

        sleep 2000

	}until !Toggle
You'll notice that there is nothing inside the "If ErrorLevel". That's where i'm having doubts. I want the program to search for a pixel and click it (that's working decently), but if it doesn't find the pixel, i want it to click on position 1, but on the next loop count, to click on position 2. The reason for this is that i'm trying to make a "bot" that kills npcs, then walks to another place to kill some more while the first spot respawns, and keep alternating between 2 spots (or more if possible!). Can anyone help me with this?

I tried to create something by tracking if the loop count was even or odd but i could'nt make it work :_ .

Thank you in advance!

User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: How to "Alternate" between different actions inside a Loop.

Post by mikeyww » 06 Oct 2022, 20:39

Welcome to this AutoHotkey forum!

Code: Select all

F4::
on := False
ToolTip
Return

F7::
on := True
CoordMode, Pixel
Coordmode, Mouse
While on {
 PixelSearch, x, y, 174, 189, 1630, 900, BGR := 0x0000FF,, Fast
 If ErrorLevel {
  ToolTip, %ErrorLevel%
  If first := !first
       Click, 100 100
  Else Click, 400 400
 } Else {
  MouseClick,, x, y
  ToolTip, Found
  Sleep, 1500
 }
 Sleep, 2000
}
Return

Post Reply

Return to “Gaming Help (v1)”