Python AttributeError:元组对象没有属性移动(OOP)
我试着正常运行代码,但是遇到了一个类似这样的错误Python AttributeError:元组对象没有属性移动(OOP),python,python-3.x,oop,pygame,attributeerror,Python,Python 3.x,Oop,Pygame,Attributeerror,我试着正常运行代码,但是遇到了一个类似这样的错误 Traceback (most recent call last): File "H:\Coursework assets\gametest1.py", line 85, in <module> wizard.move(wizard.x) AttributeError: 'tuple' object has no attribute 'move' 在游戏循环中,您创建的向导只是一个元组。创建为wizard=player(
Traceback (most recent call last):
File "H:\Coursework assets\gametest1.py", line 85, in <module>
wizard.move(wizard.x)
AttributeError: 'tuple' object has no attribute 'move'
在游戏循环中,您创建的向导只是一个元组。创建为
wizard=player(25420)
此外,强烈建议将类名大写(Player
)。有关Python社区普遍接受的更多编码风格建议,请参阅
此外,您不必在被否定的语句周围加括号,就像不是self.standing的
一样。你可能不希望不在那里,如果向导站着,你想移动他,如果他不在,你想举起他。假设你的向导是“玩家”类的,变量向导
的减速是不正确的
守则包括:
wizard = (25,420)
这使向导变成了一对数字。(称为“元组”)
我认为这应该是player
的一个实例,其x
和y
参数为25240~
wizard = player( 25, 420 )
我假设您将函数player.jump()
和player.draw()
从代码中删除,但是如果它们还没有被写入,您的主循环将中断,除了.jump()之外,与您已经报告的错误几乎相同
首先。对于变量“wizard”应该是什么,我深感困惑!您已经为它分配了一个元组,但似乎试图将其视为玩家类的实例!您的意思是设置一个名为wizard的玩家吗?在这种情况下,您需要将游戏循环的第一行替换为“wizard=player(45420)”
wizard = (25,420)
wizard = player( 25, 420 )