This is a good lesson for Python beginners. In Python, everything is an object, and objects are not copied when you make an assignment. Instead, whatever you are assigning the object to just gets a pointer to the object’s location in memory. This is very useful because it would take a lot of time and memory if Python made a full copy of an object every time you assigned it to a new variable.
For example, if you did the following:
A = [1, 2, 3]
B = A
A.append(4)
print(B)
the output would be:
[1, 2, 3, 4]
Both A and B “point” to the same list in memory. Therefore any modifications made to one affect the other.
In your case, owner.worldPosition is a Vector that the BGE’s logic loop updates every frame independent of your module. You’re able to see it changing because you’ve saved a pointer to it in the globalDict. On the other hand, calling the to_euler() method on the orientation Matrix actually creates a new object instead of getting a pointer to the same object. This new object isn’t used by the logic loop. You have the only pointer to it which is why it doesn’t change.
You should also note that with some “primitive” objects like integers, the above may seem to not hold true. For example:
A = 1
B = A
A += 2
print(B)
will still output 1. This is because “A += 2” doesn’t actually modify the object 1, it just assigns 3 to A. The same principle applies to other objects like booleans, strings, and floats.
It’s very important to know when you’re modifying an object and when you’re actually creating a new one. For example:
A = [1, 2, 3]
B = A
A = []
# print(B) will output [1, 2, 3] because A was assigned a NEW list
A = [1, 2, 3]
B = A
A.clear()
# print(B) will output [] because we have modified the list "in place"
Another example for Vectors. in the API you may have noticed that Vector has 2 methods that appear to do the same thing: normalize() and normalized(). However, normalize() normalizes the Vector IN PLACE while normalized() returns a NEW normalized copy.
If you’re ever unsure if two variables refer to the same object, you can always use the id() function which gives you the unique ID of an object.
A = 1
B = 1
print(id(A) == id(B))
# or you can use the is keyword
print(A is B)