Scratching my head ...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Mayhem
Junior Coder
Posts: 25
Joined: Tue Apr 22, 2003 6:34 pm

Scratching my head ...

Post by Mayhem » Tue Apr 20, 2004 8:25 pm

I need help to figure out what i am doing wrong ...

I'm trying to read the pixel color on a game screen to determin whether the user is playing in a small / large screen. If so, move the the approperate coords and Left Click and a bunch of other stuff .. (like killing popups)

The problem is .. it works great the first time around. When it comes to doing it the 2nd or 3rd time , its not reading pixel color location it should be reading. Thus going to Click2 sub, not Click1.

I tried reseting the x,y back to 0 each time it loops .. but i still get the same problem.

Any help would be appreciated!


Label>Start
GetWindowPos>Game room*,X,Y
Let>X=72
Let>Y=270
GetPixelColor>X,Y,PC

Label>popup
WaitWindowOpen>Your*
SetFocus>Your*
Wait>.5
Press Enter
Wait>.5
If>%PC%=10079436,Click1
If>%PC%=10276814,Click1
If>%PC%10079436,Click2
If>%PC%10276814,Click2
Let>X=0
Let>Y=0
Goto>Start

Label>Click1
....
Goto>Start

Label>Click2
...
Goto>Start

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Apr 21, 2004 1:46 am

It is not possible yet to have a complete picture of what you are doing. But it looks to me like the problem may be at the very beginning. With GetWindowPos> you are defining the values of X,Y. In the next two lines you are redefining X,Y...........for what purpose? Why bother to do GetWindowPos>?
Label>Start
GetWindowPos>Game room*,X,Y
Let>X=72
Let>Y=270
GetPixelColor>X,Y,PC
Since the window may be in different positions each time it opens, then the values of X,Y can change. Did you get the values of 72,270 from the first time it opened? I suspect you just need to eliminate those two lines and do GetPixelColor> immediately. Something like this:
Label>Start
GetWindowPos>Game room*,X,Y
GetPixelColor>%X%,%Y%,PC
But it is very likely that I don't have a complete picture. To recap, the current method looks at pixel color at 72,270 no matter where the Game room window may be positioned. The monitoring has no relationship to the position of the window.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mayhem
Junior Coder
Posts: 25
Joined: Tue Apr 22, 2003 6:34 pm

Post by Mayhem » Wed Apr 21, 2004 8:32 pm

What i was trying to do was :

a) Get the game screen position
b) Click on a button at a fixed place on the game window

Like i said in my previous post .. my script clicks the correct button the first time.

When the script goes to do it a second time, it click the wrong location. (game screen position didn't change)

Was just curious why it would work correctly the first time around, but anytime after that it doesn't.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Apr 21, 2004 10:19 pm

As I said in MY previous post:

GetPixelColor>72,270 has no relation to where the window is. Any values there are pure coincidence. You have nothing here to guarantee that X,Y are inside the game window, whether or not it moves. I would strongly encourage you to calculate GetPixelColor>X,Y based on your earlier GetWindowPos> values.

Also noticed you are later changing X,Y to 0,0, for what purpose? If some lines are being skipped, then you may be getting pixel color of 0,0 vs. 72,270. Some steps could be "skipped" because of Trailing spaces.

You never answered by earlier question:
With GetWindowPos> you are defining the values of X,Y. In the next two lines you are redefining X,Y...........for what purpose? Why bother to do GetWindowPos>?
Did you Remove All Trailing Spaces?
Did you try using variables %X%, %Y% from my earlier post?
What are the values of X,Y, PC when you single step through the macro?
Does your log show you the steps and values being processed?
Using variables in all commands will allow the log to show the values at the same time the steps are being executed.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mayhem
Junior Coder
Posts: 25
Joined: Tue Apr 22, 2003 6:34 pm

Post by Mayhem » Thu Apr 22, 2004 5:05 am

With GetWindowPos> you are defining the values of X,Y. In the next two lines you are redefining X,Y...........for what purpose? Why bother to do GetWindowPos>?
I dunno, i guess i don't know what i am doing. I'm just trying anything and everything to get this working.

I removed the trailing spaces.
Did you try using variables %X%, %Y% from my earlier post?
no because that would only give me the pixel color of 0,0 of my game window.

I cannot do a single step method because i need macro scheduler minimized for this macro to work otherwise it messes up. Too many windows are on the screen .. can't even get to that button.

Logs files show the steps being taken .. like i said in my previous post, the macro works fine the first time around ... its just every other time it does not.

This is a frustrating app to work with ..

All i want to do is :

a) get the macro to get the X,Y coords of the game screen
b) get pixel color at 72,270 relevent to that game screen

thanks for you patience in this matter .. any help wold be appreciated.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Apr 22, 2004 6:26 am

AHA...the major clue may be relevent, did you mean relative?:
b) get pixel color at 72,270 relevent to that game screen
What you need to do in concept:
Open the window.
Move the mouse to the relative position 72,720
Get the absolute coordinates of where the mouse is
Get the pixel color at that point., needs absolute coordinates

Code will look something like this, untested, possible errors:
Label>Start
WaitWindowOpen>Game room*
SetFocus>Game room*
WaitReady>1
MouseMoveRel>72,270
GetCursorPos>X,Y
GetPixelColor>%X%,%Y%,PC

If>%PC%=10079436,Click1
If>%PC%=10276814,Click1
//NOTE: According to the next 2 IF lines you will always go to Click2
If>%PC%10079436,Click2
//NOTE: If do not go to Click2 in previoius line then the next line will always do Click2 because the color must = 10079436
If>%PC%10276814,Click2
Goto>Start

Label>Click1
....
Goto>Start

Label>Click2
...
Goto>Start
NOTE 1: The comments I inserted mean you could delete both of those lines, and change the second IF> statement to this:
If>%PC%=10276814,Click1,Click2

NOTE 2: There is no exit to this macro, it will run indefinitely.

NOTE 3: You should still be able to Single Step and look at values in watch list. Key is that Focus is set to the game window. When single stepping, the focus window will acrivate, the line will execute, and the Single Step screen will come back so you can press F8 for the next step to execute.

NOTE 4: I have no explanation why it runs once only at this point, but would like to get some basic issues out of the way first.

Another reminder to Remove All Trailing Spaces if you Cut/Paste from forum.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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