Trying to eliminate sets of colors with pixel search without stopping for previous color Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
awesomite
Posts: 1
Joined: 01 Feb 2023, 09:44

Trying to eliminate sets of colors with pixel search without stopping for previous color

Post by awesomite » 01 Feb 2023, 14:51

Before everything, apologies if I don't get back right away.
I'm trying to automate a somewhat simple elimination process and am having an issue with the ability to finish a set of colors before the previous set of colors respawns and interrupts.
Elimination of these colored circles takes an unpredictable amount of time varying between instantly - 6sec~

Example 1:
Image
This is what the set up looks like initially. Every time I eliminate one circle(starting with green for example), they'll stay gone for a short period of time.
The red signal circle is something I have set up to let me know whenever I finish eliminating a circle and my script will look for that signal in order to move on to the next circle.



Example 2:
Image
This is an example of what my issue is. After eliminating some of the colors(this can happen out of order), when I'm mid way through one of the other sets, the sets prior begin to respawn.
In my script, after the red signal tells me I eliminated a circle and to move to the next, this will pull my attention away from finishing the remaining of the same color(ignoring yellow and going back to green).



Though I don't know the solution through code, my ideas to remedy this would be the ability to potentially prevent me from going back to a previous set of colors until the set of colors I'm currently eliminating are completely gone(or undetectable by script).
Any suggestions to solve any or all of the following issues would be helpful.
1: The primary issue of finishing a set of colors before moving back to a previous set.
2: Being able to immediately go to next circle without the red signal
3: A better way to organize the code or streamline it. I'm still new but as it currently runs it works pretty much fine other than issue 1.

Snippet of my current code where everything mentioned above takes place:

Code: Select all

loop {
PixelSearch, Px, Py, RedBox1, RedBox2, RedBox3, RedBox4, 0x0000FF, 1, Fast
		if (ErrorLevel = 0) {
			PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x00FF00, 1, Fast
				if (ErrorLevel = 0) {
					PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x00FF00, 1, Fast
					Random, Rx, 2, 6
					Random, Ry, 2, 6
					MouseMove, Px+Rx, Py+Ry, 3
					click
				}
				else if (ErrorLevel != 0) {
					PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x00FF88, 1, Fast
						if (ErrorLevel = 0) {
							PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x00FF88, 1, Fast
							Random, Rx, 2, 6
							Random, Ry, 2, 6
							MouseMove, Px+Rx, Py+Ry, 3
							click
						}
						else if (ErrorLevel != 0) {
							PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x0088FF, 1, Fast
								if (ErrorLevel = 0) {
									PixelSearch, Px, Py, Screen1, Screen2, Screen3, Screen4, 0x0088FF, 1, Fast
									Random, Rx, 2, 6
									Random, Ry, 2, 6
									MouseMove, Px+Rx, Py+Ry, 3
									click
								}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Trying to eliminate sets of colors with pixel search without stopping for previous color  Topic is solved

Post by swagfag » 11 Feb 2023, 20:10

Code: Select all

global Colors := { Green: 0x00FF00, PissGreen: 0xBBFF00, Yellow: 0xFFEF00 }

Loop
{
	ClickWhileEliminateeCircleVisible(Colors.Green)
	ClickWhileEliminateeCircleVisible(Colors.PissGreen)
	ClickWhileEliminateeCircleVisible(Colors.Yellow)
}

PixelSearch(x1, y1, x2, y2, colorRGB, variation) {
	PixelSearch x, y, x1, y1, x2, y2, colorRGB, variation, Fast RGB
	switch ErrorLevel
	{
	case 0: return { X: x, Y: y }
	case 1: return false
	case 2: throw Exception("There was a problem that prevented the command from conducting the search.")
	}
}

IsEliminateeCircleVisible(colorRGB) {
	global Screen1, Screen2, Screen3, Screen4
	return PixelSearch(Screen1, Screen2, Screen3, Screen4, colorRGB, 1)
}

ClickWhileEliminateeCircleVisible(colorRGB) {
	while (Coords := IsEliminateeCircleVisible(colorRGB))
		RandomizedClick(Coords.X, Coords.Y)
}

RandomizedClick(x, y) {
	MouseMove % x + Random(2, 6), % y + Random(2, 6), 3
	Click
}

Random(min, max) {
	Random r, min, max
	return r
}

Post Reply

Return to “Gaming Help (v1)”