If color=green then click x, y. So simple but doesnt work Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bergsta
Posts: 3
Joined: 27 Aug 2018, 05:54

If color=green then click x, y. So simple but doesnt work

27 Aug 2018, 06:07

So i'm automating a game and the idea is that I want to click on a in game button and if it turns green click on the next button and if it turns red click the start button again. I wrote some code based off of a color finder video and have made some simple click wait click wait scripts before. I'm honestly stumped and its probably super simple. The code I'm having troubles with goes from line 4-14 and 79-143.
Image

Code: Select all

play_Tower:
loop {
	PixelGetColor, Current_Color1, Target_X1, Target_Y1, RGB
	PixelGetColor, Current_Color2, Target_X2, Target_Y2, RGB
	PixelGetColor, Current_Color3, Target_X3, Target_Y3, RGB
	PixelGetColor, Current_Color4, Target_X4, Target_Y4, RGB
	PixelGetColor, Current_Color5, Target_X5, Target_Y5, RGB
	if (BreakLoop = 1){
  	break 
	}
	;
	MouseClick, left, 497, 810
	Sleep, 500
	MouseClick, left, 986, 778

	Sleep 500
	
	if(Current_Color1==Target_Color){
	MouseClick, left, Target_X2, Target_Y2
	}
	else if(Current_Color1!=Target_Color){
	return
	}
		
	;Second Level
	Sleep 500
	
	if(Current_Color2==Target_Color){
	MouseClick, left, Target_X2, Target_Y2
	}
	else if(Current_Color2!=Target_Color){
	return
	}	
	
	;Third Level
	Sleep 500
	
	if(Current_Color3==Target_Color){
	MouseClick, left, Target_X3, Target_Y3
	}
	else if(Current_Color3!=Target_Color){
	return
	}
	
	;Fourth Level
	Sleep 500
	
	if(Current_Color4==Target_Color){
	MouseClick, left, Target_X4, Target_Y4
	}
	else if(Current_Color4!=Target_Color){
	return
	}

	;Final Level
	Sleep 500
	
	if(Current_Color5==Target_Color){
	break
	}
	else if(Current_Color5!=Target_Color){
	return
	}
}
return
Case Clicker.ahk
(3.26 KiB) Downloaded 70 times
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: If color=green then click x, y. So simple but doesnt work  Topic is solved

27 Aug 2018, 12:23

(Foreword: I have not downloaded "Case Clicker.ahk", just using the reference code you copy and pasted to the forum.)

First off, when you find the Target_Color matches Current_Color1, you are making it click at Target_X2 and _Y2, not _X1 and _Y1. May be purposeful, but I otherwise saw a pattern that is maintained for Color2 through Color4.

Then on Color5, you force the loop to either break (and then hit the return at the very bottom) or return immediately. There can't be any looping in this scenario.

Because you did not describe what the problem was, I'm just making these guesses at two possible reasons your code is not running. Because you lack defining what these Target_ variable values are, we can't assess if there is a problem there. But your title is saying "if the color is green", which honestly, would probably an issue if you used the string "Green". If you're using a hex value like 0x0000FF, then sure, that's green and can work because CurrentColor_ values are being extracted in hex RGB format (I'm pretty sure).

A great way to diagnose your script is to look at the variables (ListVars) and also ListLines to see what steps your script is taking and what it is not.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 454 guests