Question #626564 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/626564
Status: Needs information => Answered
RaiMan proposed the following answer:
not sure if this is really your code:
def checkLastMouseLocation(currentMouseLocation):
file.write("Mouse last location\n") #DEBUG
global lastMouseLocation
global sameLocationCounter
#print("curr --> %s : last --> %s" % (currentMouseLocation,
lastMouseLocation))
if currentMouseLocation == lastMouseLocation:
sameLocationCounter += 1
else:
lastMouseLocation = currentMouseLocation
sameLocationCounter = 0
checkLastMouseLocation() ### this seems to be a copy&paste
error, because it cannot be in the code (crashes)
so your checkLastMouseLocation() is essentially this:
def checkLastMouseLocation(currentMouseLocation):
global lastMouseLocation
global sameLocationCounter
if currentMouseLocation == lastMouseLocation:
sameLocationCounter += 1
else:
lastMouseLocation = currentMouseLocation
sameLocationCounter = 0
a problem here is, that currentMouseLocation and lastMouseLocation are objects
and
currentMouseLocation == lastMouseLocation
checks wether both reference the same object and does not check any object
content for equal, like you might expect.
Equality would be:
loc1.x == loc2.x and loc1.y == loc2.y
A general problem of your code is the extensive use of globals in
functions, which makes it very hard to track down problems becaus of the
possible side effects.
Best practice is, that functions take a defined set of parameters and
return a defined return value, without any side effects. Hence such a
function will always return the same with the same parameters. This is
not guaranteed with your functions.
So until something else shows up, I say:
the problem is your
checkLastMouseLocation()
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.
_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help : https://help.launchpad.net/ListHelp