Jump to content

Need some help with my script


Recommended Posts

Hello, I am new to Autoit scripting and I need a little help.

I am trying to get my script to get a pixel with 'pixelgetcolor' then have it search other locations with 'pixelsearch'.

Next, have my 'If Not @error' run if my pixelsearch matches my pixelgetcolor. I will post my script below.

Any help would be great. :whistle:

*My Script*

Sleep(5000)

$col_1_row_1 = PixelGetColor(582,294)

$col_1_row_2 = PixelSearch(0,0,582,356,$col_1_row_1)

$col_2_row_3 = PixelSearch(0,0,632,416,$col_1_row_1)

If Not @error Then

MouseMove(582,406, 1)

MouseClick("left",582,406,)

sleep(100)

MouseMove(632,416, 1)

MouseClick("left",632,416)

EndIf

Edited by Qiman
Link to comment
Share on other sites

Hello, I am new to Autoit scripting and I need a little help.

I am trying to get my script to get a pixel with 'pixelgetcolor' then have it search other locations with 'pixelsearch'.

Next, have my 'If Not @error' run if my pixelsearch matches my pixelgetcolor. I will post my script below.

Any help would be great. :lmao:

$col_1_row_1 = PixelGetColor(582, 294)
$col_1_row_2 = PixelSearch(0, 0, 582, 356, $col_1_row_1)
$col_2_row_3 = PixelSearch(0, 0, 632, 416, $col_1_row_1)

If Not @error Then
; Whatever...
EndIf

Since the point you are getting the color from (582,294) is included in both your search areas, (0,0) to (582,356) and (0,0) to (632,416), they are both guaranteed to get a match. Is this what you intended by "...then have it search other locations"?

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

$col_1_row_1 = PixelGetColor(582, 294)
$col_1_row_2 = PixelSearch(0, 0, 582, 356, $col_1_row_1)
$col_2_row_3 = PixelSearch(0, 0, 632, 416, $col_1_row_1)

If Not @error Then
; Whatever...
EndIf

Since the point you are getting the color from (582,294) is included in both your search areas, (0,0) to (582,356) and (0,0) to (632,416), they are both guaranteed to get a match. Is this what you intended by "...then have it search other locations"?

:whistle:

Yes thats what I'm trying to do. I want to get a color from a specific location, then search for that same color in the other locations. Then if the same color is found in the other locations I want my mouse to preform certain actions. If it's not found then I want it to move on.

Sorry for the complication, I'm a total Autoit noob.

Link to comment
Share on other sites

Yes thats what I'm trying to do. I want to get a color from a specific location, then search for that same color in the other locations. Then if the same color is found in the other locations I want my mouse to preform certain actions. If it's not found then I want it to move on.

Sorry for the complication, I'm a total Autoit noob.

I'll take one more shot at it... The pixel you are getting the color from is inside the areas you are searching for the color. You are getting the color of the pixel at (582,294). You first PixelSearch() will certainly find that color at (582,294), if not sooner. Then your second search will also find the color at (582,294), if not sooner. The "If Not @error" is not really conditional then, because the second search is guaranteed to find the color.

If that IS what you wanted, then what's the question again...?

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I'll take one more shot at it... The pixel you are getting the color from is inside the areas you are searching for the color. You are getting the color of the pixel at (582,294). You first PixelSearch() will certainly find that color at (582,294), if not sooner. Then your second search will also find the color at (582,294), if not sooner. The "If Not @error" is not really conditional then, because the second search is guaranteed to find the color.

If that IS what you wanted, then what's the question again...?

:whistle:

I am thinking that I might not have approched my script correctly for what I am trying to do.

Basicly, I need to get one color, and check for matches in a given area. I would like to have 'both' areas have the matching color for the "IfNot @error to kick in. Or else will keep searching other specific areas for matches.

Hope that makes sence.

Edited by Qiman
Link to comment
Share on other sites

I am thinking that I might not have approched my script correctly for what I am trying to do.

Basicly, I need to get one color, and check for matches in a given area. I would like to have 'both' areas have the matching color for the "IfNot @error to kick in. Or else will keep searching other specific areas for matches.

Hope that makes sence.

To achieve that you have to do two things.

1. Exclude the pixel you got the color from out of the search areas (so you can match on other pixels of that color and not just the same one). Also your search areas overlap, so they might both hit on the same pixel, which doesn't sound like what you want.

2. Check @error after both searches. The @error macro is only valid for the function that most recently exited, so your test doen't tell you anything about the first search.

Here's one way you might make it work:

$col_1_row_1 = PixelGetColor(582, 294)
$col_1_row_2 = PixelSearch(0, 0, 582, 250, $col_1_row_1)
If Not @error Then
      $col_2_row_3 = PixelSearch(0, 0, 632, 250, $col_1_row_1)
      If Not @error Then
            ; Whatever...
      EndIf
EndIf

:whistle:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I have no idea what I'm doing wrong. My script is set to click only if there is not a errror, but now all of my 'If not @errors' are triggering as if everyone of the cords checked is a match, when I can see that their not. I have no idea what to do.

Here is my script so far. Maybe can see where the scripting error is.

$var1 = PixelGetColor (580,409)

$pixel = PixelSearch (0,0,580,466, $var1)

If not @error then

$pixel = PixelSearch (0,0,637,352, $var1)

If not @error then

MouseClick("left",580,352,1)

sleep (25)

MouseClick("left",637,352,1)

EndIf

EndIf

...

This is the third time telling you this, if you are not interested, stop asking about it: In most of those searches, the pixel you get the color from (i.e. 580,409 above) is inside the search areas you are checking. Of course the pixel at 580,409 matches itself, and it is included in both of the search areas, so you have to get a match at least on that pixel in both searches.

Additionally, though you didn't ask about this, when you have almost the same block of code run many times over with only small changes, you should put it in a function like this:

Sleep(5000)

$sInputData = "580, 295, 0, 0, 580, 352, 0, 0, 637, 409, 580, 409, 637, 409"
_PixelSearchAndClick($sInputData)

$sInputData = "580, 352, 0, 0, 580, 409, 0, 0, 580, 295, 580, 295, 637, 295"
_PixelSearchAndClick($sInputData)

; ...repeat as many times as required

$sInputData = "637, 295, 0, 0, 637, 352, 0, 0, 694, 409, 637, 409, 694, 409"
_PixelSearchAndClick($sInputData)


Func _PixelSearchAndClick($sInputString)
    ; Split string into an array of input numbers
    Local $avInputs = StringStripWS(StringSplit($sInputString, ","), 8)
    
    Local $iColor = PixelGetColor($avInputs[1], $avInputs[2])
    Local $RET = PixelSearch($avInputs[3], $avInputs[4], $avInputs[5], $avInputs[6], $iColor)
    If @error Then Return 0
    Local $RET = PixelSearch($avInputs[7], $avInputs[8], $avInputs[9], $avInputs[10], $iColor)
    If @error Then Return 0
    
    MouseClick("Left", $avInputs[11], $avInputs[12], 1)
    Sleep(25)
    MouseClick("Left", $avInputs[13], $avInputs[14], 1)
    Sleep(25)

    Return 1
EndFunc   ;==>_PixelSearchAndClick

I can't test it, but it shows the logic. You just put all 14 numbers you need in a string and pass it to a function to do the work.

Greatly simplifies your script, but does not solve the fact that your search boxes overlap and contain the pixel you got the color from!

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is the third time telling you this, if you are not interested, stop asking about it: In most of those searches, the pixel you get the color from (i.e. 580,409 above) is inside the search areas you are checking. Of course the pixel at 580,409 matches itself, and it is included in both of the search areas, so you have to get a match at least on that pixel in both searches.

Additionally, though you didn't ask about this, when you have almost the same block of code run many times over with only small changes, you should put it in a function like this:

Sleep(5000)

$sInputData = "580, 295, 0, 0, 580, 352, 0, 0, 637, 409, 580, 409, 637, 409"
_PixelSearchAndClick($sInputData)

$sInputData = "580, 352, 0, 0, 580, 409, 0, 0, 580, 295, 580, 295, 637, 295"
_PixelSearchAndClick($sInputData)

; ...repeat as many times as required

$sInputData = "637, 295, 0, 0, 637, 352, 0, 0, 694, 409, 637, 409, 694, 409"
_PixelSearchAndClick($sInputData)
Func _PixelSearchAndClick($sInputString)
    ; Split string into an array of input numbers
    Local $avInputs = StringStripWS(StringSplit($sInputString, ","), 8)
    
    Local $iColor = PixelGetColor($avInputs[1], $avInputs[2])
    Local $RET = PixelSearch($avInputs[3], $avInputs[4], $avInputs[5], $avInputs[6], $iColor)
    If @error Then Return 0
    Local $RET = PixelSearch($avInputs[7], $avInputs[8], $avInputs[9], $avInputs[10], $iColor)
    If @error Then Return 0
    
    MouseClick("Left", $avInputs[11], $avInputs[12], 1)
    Sleep(25)
    MouseClick("Left", $avInputs[13], $avInputs[14], 1)
    Sleep(25)

    Return 1
EndFunc   ;==>_PixelSearchAndClick

I can't test it, but it shows the logic. You just put all 14 numbers you need in a string and pass it to a function to do the work.

Greatly simplifies your script, but does not solve the fact that your search boxes overlap and contain the pixel you got the color from!

:P

Thanks for the reply. I get a "Subscript used with non-Array varriable. On line 27.

I'm a little confused about the script. If you don't mind could you give a quick explanation. I can't figure out witch cords belong to which inputs?

I think I missundertood where the cords were searching, I had no idea that they were overlaping.

I've been writing repetitive script for hours. Would save me a lot of time if I better undertood the script you gave me.

I would play around with it and see what affects what, but I have no idea how to fix this error message.

I really appreciate your help. :)

Link to comment
Share on other sites

I was thinking that there has to be a way to search for new colors and matches, that follow a pattern without having to script every change. There is probably a better way of doing this, but here is what I've come up with.

$var1 = PixelGetColor (589, 295)
$var2 = PixelGetColor (580, 352)
$var3 = PixelGetColor (637, 409)
$var4 = "580, 409"


If $var1 = $var2 Then
    If $var2 = $var3 Then
    MouseClick("left", $var3[0], $var3[1], 1 , 0)
    sleep(50)
    MouseClick("left", $var4[0], $var4[1], 1 , 0)


    
EndIf
EndIf

$Newvar1 = PixelGetColor ($var1[0], $var1[1] + 57)
$Newvar2 = PixelGetColor ($var2[0], $var2[1] + 57)
$Newvar3 = PixelGetColor ($var3[0], $var3[1] + 57)
$Newvar4 = PixelGetColor ($var4[0], $var4[1] + 57)

If $Newvar1 = $Newvar2 Then
    If $Newvar2 = $Newvar3 Then
    MouseClick("left", $Newvar3[0], $Newvar3[1], 1 , 0)
    sleep(50)
    MouseClick("left", $Newvar4[0], $Newvar4[1], 1 , 0)
EndIf
EndIf

$var1 = $Newvar1
$var2 = $Newvar2
$var3 = $Newvar3
$var4 = $Newvar4

I don't know how to loop it a certian amount of time so that I can start the new pattern. ie. I need it to loop 3 times before moving on to the next pattern.

Edited by Qiman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...