Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Game inputs skipping
#1
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)
Quote
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  looping for time while skipping a day Staph 2 277 Jun-23-2019, 03:33 AM
Last Post: Staph
  Skipping Loop blueriver649 4 391 Apr-18-2019, 04:11 AM
Last Post: blueriver649
  When I read csv file i am getting b'Skipping line messages GuJu 4 936 Mar-07-2019, 11:47 AM
Last Post: GuJu
  For loop question(skipping) jure98 1 646 Mar-31-2018, 01:54 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)