← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #265291]: some value of the variables changed with no reason

 

Question #265291 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/265291

    Status: Open => Answered

RaiMan proposed the following answer:
This is by design in object oriented programming environment, which is
true for Python/Jython and of course the underlying Java.

after
x = Region(find(picture1))

x REPRESENTS an object containing it's specific attributes like x, y, w,
h and knowing all the "globally" defined attributes and methods of the
class Region., but it is not the object itself: it is only a reference
to that object.

so after
r1 = x
r2 = x

r1, r2 and x all REPRESENT the same object (hence the result of Region(find(picture1)), which is called a reference. 
so if you change anything in r2, this will show up with r1 and x as well.

BTW: this is sufficient:
x = find(picture1)
now x represents a Match object, but this is a subclass of Region and hence has all the attributes and methods of a Region (called inheritance) plus some more, that are specific for a Match.

The solution: you have to create new objects, if you want to use the new one independently from the other:
x = find(picture1)
r1 = Region(x)
r2 = Region(x)

The Region() is called a constructor and returns a new object created
from the given parameters (in this case another Region object).

Now you have 3 different objects, that might have different attributes.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.