Hi, in my textbased game I want the player to press Enter to play and if they dont press Enter I want the code to exit and for the player to restart the game.
I watched a video about the key function and im trying to make it work from that.
def on_press(key):
if key == Key.enter:
print("Wise choice, lets play!")
return False
if key != Key.enter:
print("You pressed {0} you moron, get lost!".format(key))
quit()
with Listener(on_press = on_press) as listener:
listener.join()
time.sleep(1)
print("Game starts in 3..")
time.sleep(1)
print("2..)"
time.sleep(1)
print("1..)"
And this is where I am trying to code the continuation.
However, even if I press anything but Enter, the code continues, do I have to continue coding within the definition of on_press?
@InvisibleOne nope, still doesn't work. When I press enter it says You should of pressed enter! even though it should say lets play! Mine works fine though.
Press Enter to continue otherwise exit code
Hi, in my textbased game I want the player to press Enter to play and if they dont press Enter I want the code to exit and for the player to restart the game.
I watched a video about the key function and im trying to make it work from that.
def on_press(key):
with Listener(on_press = on_press) as listener:
listener.join()
time.sleep(1)
print("Game starts in 3..")
time.sleep(1)
print("2..)"
time.sleep(1)
print("1..)"
And this is where I am trying to code the continuation.
However, even if I press anything but Enter, the code continues, do I have to continue coding within the definition of on_press?
Here's a simpler way:
10
so:and spend all that time using ord()? That's like typing five more characters!
@IcingHackzprobs becuase I was capitalized when it wasn't supposed to, try it now.
@IcingHackzhuh, let me check
@IcingHackzOh I see, it was just me being stupid, fixed now
@IcingHackz😃
@IcingHackzhow do i make it when arrow keys are pressed e.g when left arrow key pressed then it will change the [email protected]
this is pretty outdated… and getch hates working on replit.
Just use Getkey, it’s basically the same and works great for arrow keys.
Example:
‘’’py
from getkey import getkey, keys
pressed = getkey()
if pressed == keys.UP:
print(“up arrow”)
‘’’
use keys.RIGHT, keys.LEFT, and keys.DOWN for the other arrow keys
@lumaali