I'm writing a doodle-jump terminal game for which I need to know whether or not the player has hit an obstacle. For that I'm using the instr() function to tell me if an obstacle was hit. But it doesn't register and also during debugging it doesn't activate the if-clause. Heres the python-code to my while playing function (the weird string is the player):
def play(difficulty, resize_w, resize_h):
playing = True
current_x, current_y = 10, resize_h//2
env = create_env(resize_h, resize_w)
counter = 0
while playing:
counter += 1
stdscr.clear()
print_env(env,counter)
stdscr.refresh()
stdscr.addstr(current_y,current_x,"o/00\o")
if stdscr.instr(current_y+1, current_x,1) == "=":
stdscr.addstr(5,5,"Yes")
else:
stdscr.addstr(5,5,"NO")
stdscr.timeout(60)
inp = stdscr.getch()
if inp == curses.KEY_LEFT and current_x > 0:
current_x -= 2
move_left(current_x, current_y)
elif inp == curses.KEY_RIGHT and current_x < (resize_w-6):
current_x += 2
move_right(current_x, current_y)
stdscr.instr
will return a bytes object -- bytes objects are never equal to strings (str
type) in python 3+try: