Jump to content
Sign in to follow this  
bass711

Help Please script function

Recommended Posts

bass711

Hello there, well Im trying to make my script to work but I veen moving codes up and down now im all confused

I need to get a color from a cordinate position wich is 290, 487 by a title window and then when its cordinate the color look for the same color at

781,557 area if does then move positom and left click and move on to the next color but its not sending mouse click

I think im using the "then, and endif code wrong" here is my code and thanks for your help.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Balls","")
If Not WinActive("Balls","") Then WinActivate("Balls","")
WinWaitActive("Balls","")
$x = 290
$y = 487
$COLOR = 0x15FE02;green
$COLOR1 = 0xFFFB0B;yellow
$COLOR2 = 0x20FFFC ;blue
While 1
 If  PixelGetColor(290, 487) = 0x15FE02 Then 
    PixelSearch(0,0,781,557,0x15FE02)
    EndIf
    If IsArray($COLOR)=1 Then
        MouseClick('left', $COLOR[0], $COLOR[1], 1, 4)
        Sleep(0)
        EndIf
   If PixelGetColor(290, 487)  = 0xFFFB0B  Then
    PixelSearch(0,0,781,557,0xFFFB0B)
  EndIf
  If IsArray($COLOR1)=1 Then
        MouseClick('left', $COLOR1, $COLOR1[1], 1, 4)
        Sleep(0)
EndIf
  If PixelGetColor(290, 487)  = 0x20FFFC Then
    PixelSearch(0,0,781,557,0x20FFFC)
    EndIf
 If IsArray($COLOR2)=1 Then
        MouseClick('left', $COLOR2[0], $COLOR2[1], 1, 4)
        Sleep(0)
    EndIf
        
    WEnd
Func TogglePause()
    
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites
Manjish

The first thing i noticed was this:

If IsArray($COLOR1)=1 Then
        MouseClick('left', $COLOR1, $COLOR1[1], 1, 4)
        Sleep(0)
EndIf

U are missing "[0]" for the color1 array. It should be like this:

MouseClick('left', $COLOR1[0], $COLOR1[1], 1, 4)

Also what's the need of "sleep(0)"?? It's a waste.

I also cannot see here, from where $COLOR, 1, 2 are ever going to be arrays..

Also shouldn't u need to store the result of PixelSearch in a variable n then use it in the mouseclick??

I think ur if loop is never getting true value as u clearly define $COLOR, 1, 2, as constants and not arrays..

Edited by Manjish

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
bass711

Yea I saw the error early forgot to correct but still i cant make this thing to shoot

I veen writing the code like a hundres difrents way if I least make it shoot the ball ill go from there

i know this if for a game, but i need to figure how autoit can reconise the position of my color and searxh somewhere else on the area any one Heeeeeeeeeeeelp give me a push please.

Share this post


Link to post
Share on other sites
Manjish

I think this should solve it..

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Balls","")
If Not WinActive("Balls","") Then WinActivate("Balls","")
WinWaitActive("Balls","")
$x = 290
$y = 487
While 1
If  PixelGetColor(290, 487) = 0x15FE02 Then 
    $COLOR=PixelSearch(0,0,781,557,0x15FE02)
    EndIf
    If IsArray($COLOR)=1 Then
        MouseClick('left', $COLOR[0], $COLOR[1], 1, 4)
        Sleep(0)
        EndIf
   If PixelGetColor(290, 487)  = 0xFFFB0B  Then
    $COLOR1=PixelSearch(0,0,781,557,0xFFFB0B)
  EndIf
  If IsArray($COLOR1)=1 Then
        MouseClick('left', $COLOR1[0], $COLOR1[1], 1, 4)
        Sleep(0)
EndIf
  If PixelGetColor(290, 487)  = 0x20FFFC Then
    $COLOR2=PixelSearch(0,0,781,557,0x20FFFC)
    EndIf
If IsArray($COLOR2)=1 Then
        MouseClick('left', $COLOR2[0], $COLOR2[1], 1, 4)
        Sleep(0)
    EndIf
        
    WEnd
Func TogglePause()
    
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
bass711

Thanks for the great help you support I test the code and still doesnt go, I have a question do I have to include

this code " hwnd" for pixelgetcolor when im cordinate a window title, I went back and make sure that 290 and 487 cordinates are = my colors hex and no mistake i wonder if I have to put all 4 cordinates from pixelgetcolor "0,0,0,0) and thanks one more time :)

Share this post


Link to post
Share on other sites
Manjish

No.. hwnd is optional.. it works without hwnd as well..

are u sure the hex values are the real color hex values.. because even if little variation is there, it won't work.. use the shade option in pixelsearch, to allow for certain color changes..


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
bass711

Oh I see well IM using "autoit window info" to extrack the pixel of the color u can take a look a the game

at this link

the center of the ball is 290,487 and then finds a pixel wich is equal to 0x15FE02 "green" from there it finds the same hex at related cordinate, I know at this moment green color is everwhere on top area later i will reduce the are to search maybe just a portion of the middle and thats all for cordinates, im gona try something else if that works

oh well if not Ill move on to the next test lol thanks.

Share this post


Link to post
Share on other sites
bass711

HUUULALA im close 80% really close this is cool all i have to do is center the colors in im done to bed, :)

Share this post


Link to post
Share on other sites
bass711

Ok one final question just to finish this project how do i make pixelsearch look for a center rectangle of the screen

because I read the help file and it says left top,right,bottom of a rectangle but it always start from the top left corner and i want the search pixel to look lower to the center like 565wide and 100 high, help please anyone

thanks,

Share this post


Link to post
Share on other sites
Manjish

its not necessary that rectangle starts only from top.. u can specify any rectangle.. just specify 4 co-ordinate.. 0 means 0 pixels from left.. which is the leftmost part of the screen.. if u say 30.. imagine a line 30 pixels from the leftmost part of the screen.. thats how it is..


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
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
Sign in to follow this  

×