Python Forum

Full Version: how to make a hotkey for text adventure game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm trying to make this sort of "map" key for the player to press to change their location. But I don't want to manually put in the code for every outcome I put in. I was wondering for any advice In how to make a hotkey.

NOTE: I'm a beginner just learning python so yeah I don't know much.
Is it safe to assume you are using python's native "input()" function? If you post your code it will be easier to find a solution. The basic idea would be to write some kind of mapping function that runs if input is ever a certain character. You won't have to code for every outcome, you code how the computer decides the result of the function.
name = input("Hello, Welcome to Quest Sim! Please enter your name!")
print('hello' + name)
instructions = input('Before we begin, I reccomend reading the instructions to understand how this game works press I. if you know how to play the game, press N')
if instructions == 'I':
instructions = input('Quest Sim is a word based game. that means you have to give commands when you start the game,'
'everytime their is a "" around certain words. it means its a interable command you can use.'
'just type the command to use the action. Press "Y" to return')
elif instructions == "Y" or instructions == "N":
input("The world depends on you to find the three keys to seal the darkness! to start your quest please press M")



M = str(['Beach, Mines, Town, Mansion, Home'])
x = input(m + "Select a location!")
computer = randint(0,1)
player = 3
siren = 1
if x == 'Beach':
choice1 = input("Welcome to the Beach, here lies a vast ocean fulled of critters, big and small."
'On your "Right" lies a pus fulled trail full of dead seagulls alongside the coast.'
'On your "Left" you find a injured person gasping for breath.'
'Or we can return to map to view other locations. What do you do?.')
if choice1.lower() == 'Right':
choice2 = input('You followed the trail, the stench being unable until the trail suddenly ends. You find a wild siren. you can "observe" or try to "attack" the siren. What do you do?')
if choice2 == 'Observe':
action1 = input("You notice the siren wearing a necklace around her neck, it's one of the keys of darkness!"
'it also appears that the siren is trying to sleep. there could be a small chance to "steal" the necklace from without confrontation. Worst case is that you will have to "fight"')
if action1 == 'steal':
if computer == 1:
input("You successfully took the necklace and with it the key!")


Here is my code, it's still a work in progress.