Help with Pixel please

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
JP31
Newbie
Posts: 3
Joined: Sat Aug 29, 2009 3:34 am

Help with Pixel please

Post by JP31 » Sat Aug 29, 2009 3:45 am

hi i need some help here to see how i can fix this as im trying to make it check 3 different color pixle as each pixle represent a button
and each pixle x,y cordniate is what im using as my mouse movement and they are in different location

but it doesnt seem to be working like i wanted
for example
spin x,y is 465,620 and the pixle color for that is 435151
play is 528,546 pixle color 171979
go is 494,474 pixle color 369358

how would i go about making it wait for the different button that common at different time of the game play and when those button are not found it doesnt do anything
and if play is detected i want to send key
first time play come up like send>1
second time around send>2
then loop after 2

and if it check and see these button have em click

thank you in advance i hope someone can help me in understanding

Code: Select all

WaitWindowOpen>windows®*
SetFocus>windows®*

Label>run
waitPixelColor>X,Y,PC1
If=%PC1%=435151,SPIN

getPixelColor>X,Y,PC2
If=%PC2%=171979,play

getPixelColor>X,Y,PC3
If=%PC3%=369358,Go

Label>SPIN
mousemove>465,620
LCLICK
WAIT>1
Goto>run

Label>play
MouseMove>528,546
LCLICK
WAIT>1
Goto>run

Label>go
MouseMove>494,474
LCLICK
WAIT>1
Goto>run
[code]

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Wrong syntax for WaitPixelColor and if

Post by gdyvig » Sat Aug 29, 2009 3:30 pm

HiJP31,

You are using the wrong syntax for if

Change this:

if=

To:

if>



You are using the wrong syntax for WaitPixelColor

WaitPixelColor>ColorCode,X,Y,Timeout
//WPC_RESULT wiill be TRUE if found, FALSE if not found within timeout
GetPixelColor>X,Y,PC

Change this:

waitPixelColor>X,Y,PC1
If=%PC1%=435151,SPIN

To:
Let>timeout=0.1
WaitPixelColor>435151,465,620,%timeout%
If>%WPC_RESULT%=TRUE,SPIN

Do the same for the other buttons:

Let>timeout=0.1
WaitPixelColor>171979,528,546,%timeout%
If>%WPC_RESULT%=TRUE,play


Let>timeout=0.1
WaitPixelColor>369358,494,474,%timeout%
If>%WPC_RESULT%=TRUE,go

JP31
Newbie
Posts: 3
Joined: Sat Aug 29, 2009 3:34 am

Post by JP31 » Mon Aug 31, 2009 1:17 am

thank you for that help gdyvig

here is a few problem i ran into if i leave this
WaitPixelColor>ColorCode,X,Y,Timeout
in the script it just sit there but when i remove it

i am able to get it to regonized the pixel
but for some reason it will only regonized the first pixel

as the game the button (pixel) come in at different time of the game and not always in the same order

so it would only regonized the spin but if i remove the spin from the script then my play again would work what did i do wrong please help point me in the right direction

my apoligized in advance for not understanding

Code: Select all

WaitWindowOpen>Game*
MoveWindow>Game®*,0,0
SetFocus>Game®*

Label>s1
WaitPixelColor>ColorCode,X,Y,Timeout
//WPC_RESULT wiill be TRUE if found, FALSE if not found within timeout
GetPixelColor>X,Y,PC

Let>timeout=0.01
WaitPixelColor>9495253,477,653,%timeout%
If>%WPC_RESULT%=TRUE,spin

Let>timeout=0.01
WaitPixelColor>8007569,472,578,%timeout%
If>%WPC_RESULT%=TRUE,playagain

Label>spin
MouseMoveRel>477,646
LClick
goto>s1

Label>playagain
MouseMoveRel>462,556
LClick
goto>s1


gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Your code modified to wait for each button.

Post by gdyvig » Mon Aug 31, 2009 2:39 am

Hi JP31,

Is this a different game? The color codes and coordinates are different.

I believe you are saying the game has three buttons at different locations. At least one button is displayed with the colors you provided. When the button is the color you provided it is enabled, you can click it and something will happen. If the button is not enabled, it is not displayed or changes to a different color - you did not say which, but it does not matter.

Also I believe you are saying the name of the window is always Game*, the window never disappears or changes name.

You can user WaitPixelColor with short timeouts like you are doing to find which 1, 2, or 3 of the buttons is enabled. You can use GetPixelColor instead because you are always checking.

If the first button is always displayed or if you don't wait for it to change state, your code will never look at the second button because you are always doing a goto>s1.

Code: Select all

//Try leaving out the circled R
WaitWindowOpen>Game*
MoveWindow>Game*,0,0
SetFocus>Game*

Label>s1
//Syntax of commands
//WaitPixelColor>ColorCode,X,Y,Timeout
//WPC_RESULT wiill be TRUE if found, FALSE if not found within timeout
//GetPixelColor>X,Y,PC

//Timeout for all WaitPixelColor commands
Let>timeout=0.01

Label>waitforspin
WaitPixelColor>9495253,477,653,%timeout%
If>%WPC_RESULT%=TRUE,spin

Label>waitforplayagain
WaitPixelColor>8007569,472,578,%timeout%
If>%WPC_RESULT%=TRUE,playagain

Label>spin
MouseMoveRel>477,646
LClick
//wait for button to change
//Does spin button disappear or change color?
//You may want to wait for the new color at this location

goto>waitforplayagain

Label>playagain
MouseMoveRel>462,556
LClick
//Does the playagain button disappear or change color?
You may want to wait for the new color at this location
goto>s1


Gale
Last edited by gdyvig on Mon Aug 31, 2009 3:29 am, edited 1 time in total.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Easier with subroutines

Post by gdyvig » Mon Aug 31, 2009 2:57 am

Hi JP31,

I think subroutines would make your code more organized and make it easier to check each button. It is a good practice to use gosub instead of goto whenever possible.

Code: Select all

//Try leaving out the circled R
WaitWindowOpen>Game*
MoveWindow>Game*,0,0
SetFocus>Game*

//Syntax of commands
//WaitPixelColor>ColorCode,X,Y,Timeout
//WPC_RESULT wiill be TRUE if found, FALSE if not found within timeout
//GetPixelColor>X,Y,PC

//Timeout for all WaitPixelColor commands
Let>timeout=0.01
Let>longtimeout=10

Let>xx=0
Repeat>xx
  //Do not increment xx so loop runs forever
  //This loop makes sure each button is checked
  WaitPixelColor>9495253,477,653,%timeout%
  If>%WPC_RESULT%=TRUE
      GoSub>spin
  endif

  WaitPixelColor>8007569,472,578,%timeout%
  If>%WPC_RESULT%=TRUE
     goSub>playagain
  endif

  //Add similar code for any more buttons you want to wait for

Until>xx=1

SRT>spin
  //You were waiting on 9495253,477,653
  //Are 477,636 and 477,646 the same button
  MouseMoveRel>477,646
  LClick
  WaitPixelColor>newspincolor,472,578,%longtimeout%
  //wait for button to change
  //Does spin button disappear or change color?
  //You may want to wait for the new color at this location
  //You can have a long timeout here in case game is slow
  //Long timeout will not slow down script if game is fast.
END>spin

SRT>playagain
  //You were waiting on 8007569,472,578
  //Are 472,578 and 462,556 the same button?
  MouseMoveRel>462,556
  LClick
  WaitPixelColor>newplayagaincolor,472,578,%longtimeout%
  //Does the playagain button disappear or change color?
  //You may want to wait for the new color at this location
   //You can have a long timeout here in case game is slow
  //Long timeout will not slow down script if game is fast.
END>playagain

You need to put the actual color codes in for newspincolor and newplayagaincolor. I'm not sure if this is the right thing to look for. You want to wait for something different you will see after the LCLICK.

Gale



Gale

JP31
Newbie
Posts: 3
Joined: Sat Aug 29, 2009 3:34 am

Post by JP31 » Wed Sep 02, 2009 3:27 am

thank you very much gale for the help
im still messing with it as im trying to learn and understand all these command and concept
your help is much appreciated now back to playing with it

The button disappear for all and my pixel and xy cord look different as im unsure weather to use relative and pixel together on the tools or not so thats why it look different cause one i use with out relative

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

coordinates

Post by gdyvig » Wed Sep 02, 2009 2:33 pm

Hi JP31
im unsure weather to use relative and pixel together
Your script moves the Game window to 0,0. If you leave it there when you use the cursor tool to find the coordinates the screen coordinates and the coordinates relative to the Game window will be the same.

If you want to be able to move the Game window anywhere you want it is better to use relative coordinates. When you do your mousemove you need to add the coordinate position of the Game window to the relative coordinates of your pixel within the Game window.

You should try out the FindImagePos and WaitScreenImage commands. They will find the screen coordinates (not relative coordinates) for you. Then your script does not need to worry about relative coordinates. The Game window can be anywhere on the screen. You can even move it around while the script is running.

why it look different
Are you referring to the color code changing.? It may be the pixels are dithered. That means then alternate between 2 different colors to look like a blended color.

Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts