Sikuli mouse movement location

Asked by caleb snodgrass

Hey guys,

Ok I have a script for a game which is a 2.5D game. I am harvesting some wheat, which i have coded myself, easily enough.

Now my problem is that when it clicks on one wheat it harvest it and when it goes to click on another wheat it selects a random wheat on the map. I would like it to select the wheat that is already closest to the mouse to reduce the time of my character running.

Is there a mouse location script to find location of my mouse and then run my while loop again to select the closet wheat to my character?

I hope this all makes sense.

-Caleb

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roman Podolyan (podolyan-roman) said :
#1

You can get mouse location using Env.getMouseLocation() . But I'm afraid that you had to calculate next closest yourself.

Revision history for this message
caleb snodgrass (cazam-777) said :
#2

env.getMouseLocation() works fine

If I define it by giving it a x and y co-ord as in:

env.getMouseLocation(x,y)

then can I use the code:

Env.getMouseLocation(x,y)

click((find(Pattern("FcT.png").similar(0.40))nearby(Location(x,y)))

Am I wrong here, first day of sikuli programming so I am not familiar with this coding

Revision history for this message
caleb snodgrass (cazam-777) said :
#3

Still not answered.... any help?

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Env.getMouseLocation() only returns the current location of the mouse pointer and cannot be used to set it like Env.getMouseLocation(x,y).

Use
hover(Location(x,y)) instead to move the mouse pointer to the point (x,y) on the screen.

Your challenge is rather complex for someone saying: I am not familiar with this coding.

You have to find all wheat first (may be restricted to some rectangle area around your current location) and then calculate the distance to your current location of each found wheat, to select the nearest one.

if you want to create more complex scripts beyond a series of find/wait/click, you have to dive into some scripting with Python/Jython (faq 1858) and read/understand the features of Sikuli (http://doc.sikuli.org).

Revision history for this message
John (deathhound) said :
#6

getmouseLoc = Env.getMouseLocation()
x = getmouseLoc.getX()
y = getmouseLoc.getY()
print getmouseLoc
print x
print y

Can you help with this problem?

Provide an answer of your own, or ask caleb snodgrass for more information if necessary.

To post a message you must log in.