Jump to content

Autoit Guidance


Recommended Posts

Hey whoever, I'm looking for some guidance for a autoit script I've build not related to Clash but figured there were some experiences Autoit users here.

 

The issue I'm having is I've created a function called isValid() which checks for a pixel color and if not found "false" then it should exit the function with Return. The issue is, it's not exiting and it continues to search for other pixels in the function which isn't necessary. Code below.

 

Am I simply not using autoit correctly? Just learned autoit 2 days ago after watching YouTube a couple hrs but do have a programming background.

 

func unitFind()
	;Check this color
	$Variable =  PixelSearch(1537, 919, 365, 406, 0x2C6D78, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = True Then
		selectUnit()
		MouseMove($Variable[0], $Variable[1], 50)
		sleep(250)
		MouseUp("LEFT")
		;check to see if unit succesfully placed. If check fails, end function. If succeeds, continue to next color
		Return
	EndIf

	;Check this color
	$Variable =  PixelSearch(365, 406, 1537, 919, 0x147073, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = True Then
		selectUnit()
		MouseMove($Variable[0], $Variable[1], 50)
		sleep(250)
		MouseUp("LEFT")
		;check to see if unit succesfully placed. If check fails, end function. If succeeds, continue to next color
		isValid()
	EndIf

	;Check this color
	$Variable =  PixelSearch(365, 406, 1537, 919, 0x16776E, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = True Then
		selectUnit()
		MouseMove($Variable[0], $Variable[1], 50)
		sleep(250)
		MouseUp("LEFT")
		;check to see if unit succesfully placed. If check fails, end function. If succeeds, continue to next color
		isValid()
	EndIf

	;Check this color
	$Variable =  PixelSearch(365, 406, 1537, 919, 0x327A82, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = True Then
		selectUnit()
		MouseMove($Variable[0], $Variable[1], 50)
		sleep(250)
		MouseUp("LEFT")
		;check to see if unit succesfully placed. If check fails, end function. If succeeds, continue to next color
		isValid()
	EndIf


	;Check this color
	$Variable =  PixelSearch(365, 406, 1537, 919, 0x15736E, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = True Then
		selectUnit()
		MouseMove($Variable[0], $Variable[1], 50)
		sleep(250)
		MouseUp("LEFT")
	EndIf
EndFunc



func isValid()
	;Check this color
	$Variable =  PixelSearch(463, 845, 465, 847, 0x1C8616, 1)
	;if found, try to place unit in valid location
	If IsArray($Variable) = False Then
		Return
	EndIf
EndFunc

 

Link to post
Share on other sites

Less code :

 

Func UnitFind()

	; An Array with all necessary colors and positions to use in PixelSearch
	Local $aVariable[5][6] = [[1537, 919, 365, 406, 0x2C6D78, 1], [365, 406, 1537, 919, 0x147073, 1], [365, 406, 1537, 919, 0x16776E, 1], _
			[365, 406, 1537, 919, 0x327A82, 1], [365, 406, 1537, 919, 0x15736E, 1]]

	Local $iDelay = 250

	For $i = 0 To UBound($aVariable) - 1
		; Checking all previous array var, Check colors and positions
		Local $aResult = PixelSearch($aVariable[$i][0], $aVariable[$i][1], $aVariable[$i][2], $aVariable[$i][3], $aVariable[$i][4], $aVariable[$i][5])
		; Check any possible error , idk if is to 'continueloop' or just 'ExitLoop' your choice! 
		If @error Then ContinueLoop
		; Just in case is not an array and doesn't have 2D
		If Not IsArray($aResult) Or UBound($aResult) <> 2 Then ContinueLoop
		selectUnit()
		MouseMove($aVariable[$i][0], $aVariable[$i][1], 50)
		Sleep($iDelay)
		MouseUp("LEFT")
        ; Maybe a new delay will be necessary
        Sleep($iDelay)
		; Verify if exist a color in a position
		If Not isValid() Then ExitLoop
	Next

EndFunc   ;==>UnitFind

; Booelan function
Func isValid()
	;Check color
	Local $aResult = PixelSearch(463, 845, 465, 847, 0x1C8616, 1)
	If @error Then Return False
	If Not IsArray($aResult) Or UBound($aResult) <> 2 Then Return False
	Return True
EndFunc   ;==>isValid

 

Edited by MAJPA
  • Like 1
Link to post
Share on other sites
5 hours ago, MAJPA said:

Less code :

 

Func UnitFind()

	; An Array with all necessary colors and positions to use in PixelSearch
	Local $aVariable[5][6] = [[1537, 919, 365, 406, 0x2C6D78, 1], [365, 406, 1537, 919, 0x147073, 1], [365, 406, 1537, 919, 0x16776E, 1], _
			[365, 406, 1537, 919, 0x327A82, 1], [365, 406, 1537, 919, 0x15736E, 1]]

	Local $iDelay = 250

	For $i = 0 To UBound($aVariable) - 1
		; Checking all previous array var, Check colors and positions
		Local $aResult = PixelSearch($aVariable[$i][0], $aVariable[$i][1], $aVariable[$i][2], $aVariable[$i][3], $aVariable[$i][4], $aVariable[$i][5])
		; Check any possible error , idk if is to 'continueloop' or just 'ExitLoop' your choice! 
		If @error Then ContinueLoop
		; Just in case is not an array and doesn't have 2D
		If Not IsArray($aResult) Or UBound($aResult) <> 2 Then ContinueLoop
		selectUnit()
		MouseMove($aVariable[$i][0], $aVariable[$i][1], 50)
		Sleep($iDelay)
		MouseUp("LEFT")
        ; Maybe a new delay will be necessary
        Sleep($iDelay)
		; Verify if exist a color in a position
		If Not isValid() Then ExitLoop
	Next

EndFunc   ;==>UnitFind

; Booelan function
Func isValid()
	;Check color
	Local $aResult = PixelSearch(463, 845, 465, 847, 0x1C8616, 1)
	If @error Then Return False
	If Not IsArray($aResult) Or UBound($aResult) <> 2 Then Return False
	Return True
EndFunc   ;==>isValid

 

Wow thank you both, I was wondering if there was a way to simply put the hex colors in an array. So question, if all the search locations are the same I could just load up an array with nothing but hex and loop through the list? Purpose would be the maps change that I am writing this for and I need to find unit placement. The shades of colors are very odd and the patterns are difficult to locate. Placement locations vary only specific HEX colors are considered valid placement. Map changes each load >.<

Link to post
Share on other sites
13 hours ago, JanqeD said:

So question, if all the search locations are the same I could just load up an array with nothing but hex and loop through the list? 

 

Yes 

something like :

; Just the colors
Local $aColors[4] = [0x147073, 0x16776E, 0x327A82, 0x15736E], $aResult

For $i = 0 To UBound($aColors) - 1
	$aResult = PixelSearch(365, 406, 1537, 919, $aColors[$i], 1)
	If @error Then ContinueLoop
	If Not IsArray($aResult) Or UBound($aResult) <> 2 Then ContinueLoop
Next

 

13 hours ago, JanqeD said:

 The shades of colors are very odd and the patterns are difficult to locate. Placement locations vary only specific HEX colors are considered valid placement. Map changes each load >.<

 

Maybe what you need is Image detection and not Pixel Search!!

 

see the https://github.com/MyBotRun/Libraries 

Maybe you can use the ImgLoc , is my suggestion  https://github.com/MyBotRun/Libraries/tree/master/ImgLOC/ImgLoc

 

Edited by MAJPA
  • Upvote 1
Link to post
Share on other sites

I was thinking the same thing would be idea but am unsure if it would work. I tried with simple ImageSearch and failed horribly. Could I pm you with the concept of the application and explain why the ImageSearch failed. Different package so maybe the one CoC uses is better for use for me.. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...