0

Receiving a TypeError when trying to run:

File "/home/XX/PycharmProjects/rogue_like/venv/lib64/python3.7/site-packages/tcod/libtcodpy.py", line 1236, in console_put_char
    lib.TCOD_console_put_char(_console(con), x, y, _int(c), flag)
TypeError: an integer is required
Class Object:

    def __init__(self, x, y, char, color):
        self.x = x
        self.y = y
        self.char = char
        self.color = color

    def draw(self):
        libtcod.console_set_default_foreground(con, self.color)
        libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)

# later...

SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, '@', libtcod.yellow)

Following a roguelike tutorial and ran into this. Have tried passing an integer by changing the '@' to a number and other things. Have tried handing it to int(self.char) and other options but seem to be hitting a wall.

Any help would be great! Tried to include pertinent code, let me know if there's anything else.

EDIT:

"""
...
   Args:
    con (Console): Any Console instance.
    x (int): Character x position from the left.
    y (int): Character y position from the top.
    c (Union[int, AnyStr]): Character to draw, can be an integer or string.
    flag (int): Blending mode to use, defaults to BKGND_DEFAULT.
"""
lib.TCOD_console_put_char(_console(con), x, y, _int(c), flag)
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

2

In Python 3, dividing two ints always produces a float, so 80/2 and 50/2 are producing floats, not ints. To make them ints, you could either use floor division (80//2) or cast to int (int(80/2)).

I guess your tutorial is for Python 2, cause in Python 2, dividing two ints always produces an int.

More details

wjandrea
  • 28,235
  • 9
  • 60
  • 81