Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么libtcod.console“u put”u char不断返回;ctypes.ArgumentError“;_Python_Ctypes_Libtcod - Fatal编程技术网

Python 为什么libtcod.console“u put”u char不断返回;ctypes.ArgumentError“;

Python 为什么libtcod.console“u put”u char不断返回;ctypes.ArgumentError“;,python,ctypes,libtcod,Python,Ctypes,Libtcod,到目前为止的代码: 运行代码时,我得到错误: Traceback (most recent call last): File "C:/Users/Tyler/Documents/Third Party Games/Python/RogueLike/RogueLike.py", line 224, in <module> render_all() File "C:/Users/Tyler/Documents/Third Party Games/Python/RogueLike/Rog

到目前为止的代码:

运行代码时,我得到错误:

Traceback (most recent call last):
File "C:/Users/Tyler/Documents/Third Party Games/Python/RogueLike/RogueLike.py", line 224, in <module>
render_all()
File "C:/Users/Tyler/Documents/Third Party Games/Python/RogueLike/RogueLike.py", line 173, in render_all
object.draw()
File "C:/Users/Tyler/Documents/Third Party Games/Python/RogueLike/RogueLike.py", line 69, in draw
libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
File "C:\Users\Tyler\Documents\Third Party Games\Python\RogueLike\libtcodpy.py", line 765, in console_put_char
_lib.TCOD_console_put_char(con, x, y, ord(c), flag)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2
它不喜欢self.x或self.y

我在第213行遇到了类似的问题:

player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT, "@", libtcod.white)
但我设法巧妙地解决了这个问题,用实际值代替SCREEN_WIDTH和SCREEN_HEIGHT,而不是变量名


但是,我似乎无法用这种方式解决当前的问题。

请注意返回浮点值的操作。在Python3中,除法运算符
/
是真除法(
\uuuu-truediv\uuu
),而不是经典除法(
\uu-div\uu
)。所以
SCREEN\u WIDTH/2
是一个
float
。类似地,在
center
方法中,表达式
(self.x1+self.x2)/2
是一个浮点值。Python 2.2引入了floor division(
\uu floordiv\uu
)操作符
/
。使用此运算符可以实现整数除法,例如
SCREEN\u WIDTH//2
@eryksun非常感谢,它完美地解决了这个问题
player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT, "@", libtcod.white)