Jump to content

Predefined Area for Pixelsearch


Go to solution Solved by BrewManNH,

Recommended Posts

i try to shorten my work a little by using predefined areas for PixelSearch.
There are several defined areas that need to be searched for defined colors. so what i did was to "Global" the area coordinates.

like this:

Global $slot1 = "63,227,212,396"
Global $slot2 = "218,227,366,393"   
Global $slot3 = "372,227,520,396"   
Global $slot4 = "63,409,212,578"    
Global $slot5 = "218,409,366,578"

and the colors too:

Global $color_jobdone = "0x10CA22"

Now i want to use PixelSearch without typing all these numbers again. something like this:

PixelSearch ($Slot1,$color_jobdone)
If @error Then 
   Msgbox (1,"Yes","")
EndIf
PixelSearch ($Slot1)
If Not @error Then
   MsgBox (1,"No","")
EndIf

Is it possible to use the 4 coordinate numbers in 1 $var to ease up the work? if it is,... how?

Link to comment
Share on other sites

make an array. here's an example i just made with the first set of number you posted:

Global $aArray[4] ;Creates an array that can hold 4 values
$aArray[0] = 63 ;arrays are zero based, so the first value is [0]
$aArray[1] = 227
$aArray[2] = 212
$aArray[3] = 396

;if you want to use these values, simply use the variable as normal but you will need to specify the array entry

MsgBox(0, "$aArray[0]", "The value stored in $aArray[0] is: " & $aArray[0])

; if you want to step through each value in the array, use a For loop

For $i = 0 to 3 Step 1 ;$i is going to be our index indicator. since $aArray starts at 0, thats where we want to start
    MsgBox(0, "$aArray[" & $i & "]", "The value stored in $aArray[" & $i & "] is: " & $aArray[$i])
    ;notice that i put $i in place of the index number.
Next
Edited by Kidney
Link to comment
Share on other sites

thanks, kidney.
i mentioned above, that i am using arrays now. almost as you described. slightly different. i used it this way:
 

#include <Array.au3> 
Global $sl1 = _ArrayCreate(0,63,227,212,396)
Global $sl2 = _ArrayCreate(0,218,227,366,393)   
Global $sl3 = _ArrayCreate(0,372,227,520,396)   
Global $sl4 = _ArrayCreate(0,63,409,212,578)
Global $sl5 = _ArrayCreate(0,218,409,366,578)

the first array is set to 0, cos i dont like the $a[0] thing. the first array should be [1]. but thats a personal opinion.

however, this method makes it easyer to control large ammount of coordinates.

PixelSearch ($sl1[1],$sl1[2],$sl1[3],$sl1[4],$color_jobdone)
PixelSearch ($sl1[1],$sl1[2],$sl1[3],$sl1[4],$color_jobdone)
PixelSearch ($sl1[1],$sl1[2],$sl1[3],$sl1[4],$color_button)
PixelSearch ($sl2[1],$sl2[2],$sl2[3],$sl2[4],$color_jobdone)
PixelSearch ($sl2[1],$sl2[2],$sl2[3],$sl2[4],$color_button)
PixelSearch ($sl3[1],$sl3[2],$sl3[3],$sl3[4],$color_jobdone)

is easyer to write than

PixelSearch (60,200,80,300,0x030303)
PixelSearch (480,320,550,600,0xB13103)
PixelSearch (480,320,550,600,0xB13103)
PixelSearch (60,200,80,300,0x030303)
PixelSearch (480,320,550,600,0xB13103)

But it is still far away from

 

PixelSearch ($slot1,$color)
PixelSearch ($slot2,$color)
PixelSearch ($slot3,$color)

^This is what i am trying to achieve. but i guess, i have to go with the arrays.

anyhow. 12 hours of writing, made me tired now, and gave me a lot of headache.

Thanks for your help!

Edited by ChristianGeissenhoener
Link to comment
Share on other sites

  • Solution

#include <Array.au3>
Global $sl[5][5] = [[0,63,227,212,396], [0,218,227,366,393], [0,372,227,520,396], [0,63,409,212,578], [0,218,409,366,578]]
_ArrayDisplay($sl)
For $Loop = 1 to 5
    PixelSearch($sl[$Loop][1], $sl[$Loop][2], $sl[$Loop][3], $sl[$Loop][4], $sl[$Loop][5])
Next

Much more reasonable to use the arrays correctly.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@ChristianGeissenhoener

i think what you r trying to do is to make a new function of your own that calls the PixelSearch function but with your own parameters.

here is what i think you r trying to do:

Global $aArray[4] = [0,0,1920,1080]
$color = 0xA9100A
$result = _PixelSearch($aArray, $color)
MouseMove($result[0], $result[1])
MsgBox(0, "Result", $result[0] & " " & $result[1])

Func _PixelSearch($aCoords, $colorID)
        Return PixelSearch($aCoords[0], $aCoords[1], $aCoords[2], $aCoords[3], $colorID)
EndFunc
Link to comment
Share on other sites

 

@ChristianGeissenhoener

i think what you r trying to do is to make a new function of your own that calls the PixelSearch function but with your own parameters.

here is what i think you r trying to do:

Global $aArray[4] = [0,0,1920,1080]
$color = 0xA9100A
$result = _PixelSearch($aArray, $color)
MouseMove($result[0], $result[1])
MsgBox(0, "Result", $result[0] & " " & $result[1])

Func _PixelSearch($aCoords, $colorID)
        Return PixelSearch($aCoords[0], $aCoords[1], $aCoords[2], $aCoords[3], $colorID)
EndFunc

this is an almost perfect, ... maybe perfect solution.

a new day of rewriting than. ... AutoIt is so exciting for an old man. Thanks a lot creators, and thanks a lot communty here.

and in this particular case, thank you very much Kidney!

Link to comment
Share on other sites

#include <Array.au3>
Global $sl[5][5] = [[0,63,227,212,396], [0,218,227,366,393], [0,372,227,520,396], [0,63,409,212,578], [0,218,409,366,578]]
_ArrayDisplay($sl)
For $Loop = 1 to 5
    PixelSearch($sl[$Loop][1], $sl[$Loop][2], $sl[$Loop][3], $sl[$Loop][4], $sl[$Loop][5])
Next

Much more reasonable to use the arrays correctly.

i didn't get this first. it was over my ability. after writing functions where only 1 number in the $sl changed, i took some time to think about this solution. and... this one is really perfect. without a maybe.

Link to comment
Share on other sites

Just remember, that snippet is just a demonstration of how to do it, there would need to be more work involved to make it do what you're looking for. Such as assigning a variable to the PixelSearch return, checking for any errors when the pixel isn't found, jumping to a function if it is, etc. But at least the foundation is there, now time to build the house. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...