Page 1 of 1

Help with If and PixelSearch

Posted: 06 Jan 2018, 07:56
by Traurig
Hi folks!

So I'm stumped. Here's roughly what I want to happen, all at the same time.

1. AHK refreshes in-game trader inventory (one click)
2. AHK scrolls through inventory (one click every ~800ms to allow for PixelSearch to properly function)
3. AHK interrupts normal loop (scrolling through inventory, refreshing inventory) when it notices pixel of certain color as defined by PixelSearch
4. Upon noticing, starts new routine to click pixel (item), click another two buttons to confirm sale
5. Once sale is complete, return to previous loop and start at step 1.

Hopefully that's clear enough. Here's my code. I have a feeling that certain things are looping and PixelSearch is being ignored in favor of the "Else" section of the expression. I just can't wrap my head around the logic unfortunately. Any help appreciated!

As of right now, the loop just scrolls through (and refreshes) the trader inventory (the 'Else' portion of the code). It does not seem to be paying any attention to the persistent (my goal) pixel searching.

Code: Select all

CoordMode, Pixel, Screen
#singleInstance, Force

z::  ; press F8 to toggle the loop on/off.
Loop
{
	PixelSearch, colourx, coloury, 0, 0, 583, 1033, 0x071C67, 0, Fast
	If ErrorLevel = 0
		{
		Click, %colourx%, %coloury%
		sleep 200
		Click, 826, 986
		sleep 200
		Click, 851, 185
		sleep 2000
		}
	Else
		Click, 282, 95
		sleep 1000
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 419
		sleep 800
		Click, 527, 519
		sleep 800
		Click, 527, 619
		sleep 800
		Click, 527, 719
}
return
x::
ExitApp

Re: Help with If and PixelSearch

Posted: 06 Jan 2018, 15:25
by Xtra
The else portion of your script needs to be in a code block using { }

Code: Select all

	Else
	{
		Click, 282, 95
		sleep 1000
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 277
		sleep 30
		Click, 527, 419
		sleep 800
		Click, 527, 519
		sleep 800
		Click, 527, 619
		sleep 800
		Click, 527, 719
	}