Problems with scripting

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
j3ron
Newbie
Posts: 2
Joined: Sun Jan 27, 2008 9:02 am

Problems with scripting

Post by j3ron » Sun Jan 27, 2008 9:15 am

Hi.

I was wondering if anyone could see the problem with the following script.
The wanted functionality is that it
1. grabs a screenshot of a smaller section of the screen.
2. Checks for one of 2 different images - (question 1 or question2)
3. Depending on which question it is (1 or 2) looks in the same screenshot for a specific image (answer) and then clicks the middle of this image (answer).

GetScreenRes>sX,sY
ScreenCapture>820,450,1260,700,d:\BG.bmp
FindImagePos>D:\q1.bmp,D:\BG.bmp,20,0,,,q1
If>q1>0
FindImagePos>D:\a1.bmp,D:\BG.bmp,20,1,XPos,YPos,a1
Endif
MouseMove>XPos_0,Ypos_0
LClick
Else
FindImagePos>D:\q2.bmp,D:\BG.bmp,20,0,,,q2
If>q2>0
FindImagePos>D:\a2.bmp,D:\BG.bmp,20,1,XPos2,YPos2,a2
Endif
MouseMove>XPos_0,YPos_0
LClick
Endif

With this script i get a "Invalid Numeric Value for MouseMove command"

If i move the Endif's down 2 lines to after the LClick command i do not get any error message, but nothing happens whatsoever.

Any help would be greatly appreciated, this program is really awesome, but i'm just not sure if I just suck at scripting or what the problem is.

Cheers, Jesper

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Jan 27, 2008 2:35 pm

Hi,

1. The cause of the error is that your second MouseMove attempts to move to XPos_0,YPos_0 but no such variables exist at this point. The final FindImagePos statement to which this MouseMove appears to relate uses return vars XPos2 and YPos2. Therefore your MouseMove needs to move to XPos2_0,YPos2_0.

2. Your If/Else/Endif statements are all confused. I *think* what you really mean to do is as I have done in the code below.

3. You should really check that an image is found after the FindImagePos statements inside your If statements - you need extra If statements

4. You are searching an area of the screen, not the entire screen. The FindImagePos command will return the coordinates within THAT image, relative to 0,0. These will NOT be screen coordinates since your haystack image starts at screen position 820,450. So to convert to screen coordinates you should add 820,450 to the returned coordinates.

All the above taken into account, plus some guess work based on your odd looking if blocks, your script should probably look like this:

Code: Select all

GetScreenRes>sX,sY
ScreenCapture>820,450,1260,700,d:\BG.bmp
FindImagePos>D:\q1.bmp,D:\BG.bmp,20,0,,,q1
If>q1>0
  FindImagePos>D:\a1.bmp,D:\BG.bmp,20,1,XPos,YPos,a1
  If>a1>0
    MouseMove>{%XPos_0%+820},{%Ypos_0%+450}
    LClick
  Endif
Else
  FindImagePos>D:\q2.bmp,D:\BG.bmp,20,0,,,q2
  If>q2>0
    FindImagePos>D:\a2.bmp,D:\BG.bmp,20,1,XPos2,YPos2,a2
	If>a2>0
      MouseMove>{%XPos2_0%+820},{%YPos2_0%+450}
      LClick
	Endif
  Endif
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

j3ron
Newbie
Posts: 2
Joined: Sun Jan 27, 2008 9:02 am

Post by j3ron » Sun Jan 27, 2008 9:41 pm

Perfect - it worked like a charm. Thanks a bunch.

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