This is really weird, but I'm making a custom vector using pygame's Vector2 as a parent, and any attempt to define an attribute that starts with the letters x or y results in an error upon initialization. If the x is anywhere else in the attribute name, it works fine.
For example, this works fine:
class CustomVector(pygame.Vector2):
def __init__(self,vector,attribute):
super().__init__(vector)
self.attribute = attribute
CustomVector((0,0),True)
This also works fine:
class CustomVector(pygame.Vector2):
def __init__(self,vector,attribute):
super().__init__(vector)
self.attributex = attribute
CustomVector((0,0),True)
But this raises an error:
class CustomVector(pygame.Vector2):
def __init__(self,vector,attribute):
super().__init__(vector)
self.xattribute = attribute
CustomVector((0,0),True)
The error raised is generally TypeError: a sequence is expected, but I've gotten others
Per John Gordon, here is the whole error message. There is another error, but it is clearly stated that it is the direct result of the TypeError:
TypeError: a sequence is expected
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\ajhom\Documents\Monster\code\test.py", line 14, in <module>
CustomVector((0,0),True)
~~~~~~~~~~~~^^^^^^^^^^^^
SystemError: <function CustomVector.__init__ at 0x000002B7C347EDE0> returned a result with an exception set
pygame.math.Vector2? pygame.org/docs/ref/math.html#pygame.math.Vector2x,y,z, andwonly: for example, you can assign a 2-element tuple to the attributeyxif the coordinates are in the opposite order from what you want to put in the Vector. There is a fallthrough to handle attribute names like yours - but it only gets checked after values have been retrieved for thexyzwcharacters in the name, so the assignment fails if the value wasn't a tuple or other sequence of sufficient length.