So, my code is this bad boy here
#!/usr/bin/env python3
import tcod
def main() -> None:
screen_width = 80
screen_height = 50
tiileset = tcod.tileset.load_tilesheet(
"dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
)
with tcod.context.new_terminal(
screen_width,
screen_height,
tileset=tiileset,
title = "Yet Another Roguelike Tutorial",
vsync=True,
) as context:
root_console = tcod.Console(screen_width, screen_height, order="F")
while True:
root_console.print(x=1,y=1,string="@")
context.present(root_console)
for event in tcod.event.wait():
if event.type == "QUIT":
raise SystemExit()
if __name__ == "__main__":
main()
I should see an @ when I run the code with python3, but, instead, it gives me this message
"AttributeError: 'Context' object has no attribute '_context_p'"
It sort of sounds obvious what's the problem, but I can't figure out how to solve, can you folks help me?
EDIT: The problem was the indentation on some lines
with tcod.context.new_terminal(
screen_width,
screen_height,
tileset=tiileset,
title = "Yet Another Roguelike Tutorial",
vsync=True,
) as context:
root_console = tcod.Console(screen_width, screen_height, order="F")
while True:
root_console.print(x=player_x,y=player_y,string="@") #defines the player (in this case is this @)
context.present(root_console)
root_console.clear() #clears path behind our player
for event in tcod.event.wait():
action = event_handler.dispatch(event)
if action is None:
continue
if isinstance(action, MovementAction):
player_x += action.dx
player_y += action.dy
elif isinstance(action, EscapeAction):
raise SystemExit()
It should be this way, this is why it wasn´t working, and it was a syntax error that was preventing it from running properly