Python Forum

Full Version: Game inputs skipping
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey, I am trying to make a game in python. I am by no means a good programmer so I am very sorry if my terminology is incorrect, or my code is just not good in general. Anyway, my game is supposed to work as follows, the game would tell you about the scenario, you enter a response. There will be two defined answers, with a few exceptions just in case of typos, one defined answer should allow you to continue, while the other provides a different text but allows you to re answer. Every time you use the correct answer that progresses the story, it should provide a second response and either change or delete the previous version of the input, making it so you cant re answer the same prompts over again, or skip prompts. But because of the way it is, for some reason it wont let me get past my first prompt at all if I use an incorrect input, and on the second prompt it always skips that as well. oh, and any undefined input should respond with "I'm sorry, I do not understand." Once again, sorry for being a newb, thanks for the help!

import sys,time,random
def print_slow(str):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(0.025)

print_slow("You pull up to your old childhood house. It is 3 am and you are exauhsted. You havent been here in six years. You are back because your mother mailed you a note, with a key saying that there is a present waiting for you inside. The key and the note are in the glovebox. Taking off your seatbelt and turning off the car, you sit in the silence.")
print("")
print("")

userInput = input("EnterCommand:")

#First Option
   
if userInput == "leave car":
    print_slow("you can't get in the house without the key, so you might want to grab that first.")
    print ("")
    print(userInput)
    
elif userInput == "Leave car":
    print_slow("you can't get in the house without the key, so you might want to grab that first.")
    print("")
    print(userInput) 
    
elif userInput == "Leave Car":
    print_slow("you can't get in the house without the key, so you might want to grab that first.")
    print("")
    print(userInput) 
    
userInput2 = input("EnterCommand:")
 
if userInput == "open glovebox":
    print_slow("You open the glovebox and grab the key and note, clutching them to your chest. Read the note?")
    print("")
    print(userInput2)
    
elif userInput == "Open glovebox":
    print_slow("You open the glovebox and grab the key and note, clutching them to your chest. Read the note?")
    print("")
    print(userInput2)
    
elif userInput == "Open Glovebox":
    print_slow("You open the glovebox and grab the key and note, clutching them to your chest. Read the note?")
    print("")
    print(userInput2)
    

else:
    print_slow("I'm sorry, I do not understand")
    print ("")
    print(userInput) 

if print(userInput2):
    del (userInput)

#Second Option

if userInput2 == "Read note":
    print_slow("Hey fflkfa, we missed you so much! Its been a long time since we saw you, and we hope you're doing much better. Its such a shame...but anyway, we have a gift waiting in your old room! we hope you love it!. [the paper is old and yellow, smelling musty.] ")
    print("")
    print(userInput2)
    
elif userInput2 == "read note":
    print_slow("Hey kfljaf, we missed you so much! Its been a long time since we saw you, and we hope you're doing much better. Its such a shame...but anyway, we have a gift waiting in your old room! we hope you love it!. [the paper is old and yellow, smelling musty.] ")
    print("")
    print(userInput2)
    
elif userInput2 == "Read Note":
    print_slow("Hey fklafa, we missed you so much! Its been a long time since we saw you, and we hope you're doing much better. Its such a shame...but anyway, we have a gift waiting in your old room! we hope you love it!. [the paper is old and yellow, smelling musty.] ")
    print ("")
    print(userInput2)
    
userInput3 = input("EnterCommand:")
  
if userInput2 == "Leave car":
    print_slow("You get out of your car and breath in the air of your old home...so familiar, it makes your heart lift a little bit, as you take in the memories. Despite no one living there for years, the place was kept in great condition.")
    print("")
    print(userInput3)
        
    
elif userInput2 == "Leave Car":
    print_slow("You get out of your car and breath in the air of your old home...so familiar, it makes your heart lift a little bit, as you take in the memories. Despite no one living there for years, the place was kept in great condition.")
    print("")
    print(userInput3)
        
    
elif userInput2 == "leave car":
    print_slow("You get out of your car and breath in the air of your old home...so familiar, it makes your heart lift a little bit, as you take in the memories. Despite no one living there for years, the place was kept in great condition.")
    print ("")
    print(userInput3)
    
    
else:
    print_slow("I'm sorry, I do not understand")
    print ("")
    print(userInput2)
You really need a loop that keeps track of the state of the game. The format you are using is far too restrictive. For example, you can't open the glovebox until you try to open the car and fail. I would strongly suggest reading the text adventure tutorial linked to in my signature.

Also, the standard way in Python for case insensitive text matching is to use the lower method of the input string, which makes it all lowercase:

if userInput.lower() == 'leave car':
    # do stuff
The above code covers all three cases you have in your code. This allows to not repeat code. Repeating code is a bad idea, it is an invitation for bugs and inconsistencies.
Thanks for the assistance, Craig. Ill try that. My teacher is having us use python this year but gave us virtually no training whatsoever, and whenever I ask for help they are usually very vague about it. If I have post again if I have any more difficulty.