Tyrone Pope
Tyrone Pope

Reputation: 81

My word checking system for my Text Based Game does not work

I am having an issue with a Text Based Game I am making for my AP Computer Science principals project. What's supposed to happen is this line of code:

def pI(options):
    #PI stands for Player Input 
    playerInput = (input("==> "))

    if playerInput not in options or commands:
        print(playerInput + " is not a possible option")
        print("Do /options for a list of acceptable options") 
        playerInput = (input("==> "))

    if playerInput == "/commands":
        print(commands)
    elif playerInput == "/options":
        print("Acceptable inouts are" + options)
    elif playerInput == "/help":
        gHelp()

    return(playerInput)

is supposed to check if the player's input is one that can be done. However, with this system, the interpreter does not even check the playerInput. I don't get any errors, but it's not working the way i want it to. The logic makes sense to me, but not the interpreter. Does anyone know why this is? Here is the rest of my code so far for the game if that helps:

#Made by -----------------------------------------------------------#
import sys
import os
import time
import random

os.system("mode con: cols=45 lines=80")
#Commands-----------------------------------------------------------#
commands = ["/options, /Help"]
#Functions----------------------------------------------------------#
def save():
    print("This is supposed to save, but it doesn't work yet")

def clear():
    os.system('cls')

def back():
    pCS

def pI(options):
    #PI stands for Player Input 
    playerInput = (input("==> "))

    if playerInput not in options or commands:
        print(playerInput + " is not a possible option")
        print("Do /options for a list of acceptable options") 
        playerInput = (input("==> "))

    if playerInput == "/commands":
        print(commands)
    elif playerInput == "/options":
        print("Acceptable inouts are" + options)
    elif playerInput == "/help":
        gHelp()

    return(playerInput)
#Graphics-----------------------------------------------------------#
  #All Graphic functions start with "g" so that i don't take any 
  #names I might need later

def gLine():
    #Function Draws lines 
    ps2("******************************************************************************************************************")

def gHeader():
    gLine()
    ps2(""" 
___________.__              __      __               __  .__             _____  __________      .__                 
\__    ___/|  |__   ____   /  \    /  \___________ _/  |_|  |__    _____/ ____\ \____    /____  |  |   ____   ____  
  |    |   |  |  \_/ __ \  \   \/\/   |_  __ \__  \\   __\  |  \   /  _ \   __\    /     /\__  \ |  |  / ___\ /  _ \ 
  |    |   |   Y  \  ___/   \        / |  | \// __ \|  | |   Y  \ (  <_> )  |     /     /_ / __ \|  |_/ /_/  >  <_> )
  |____|   |___|  /\___  >   \__/\  /  |__|  (____  /__| |___|  /  \____/|__|    /_______ (____  /____|___  / \____/ 
                \/     \/         \/              \/          \/                         \/    \/    /_____/         """)
    gLine() 

def gExit():
    clear()
    save()
    gLine()
    ps2("""
___________      .__  __  .__                                     
\_   _____/__  __|__|/  |_|__| ____    ____                       
 |    __)_\  \/  /  \   __\  |/    \  / ___\                      
 |        \>    <|  ||  | |  |   |  \/ /_/  >                     
/_______  /__/\_ \__||__| |__|___|  /\___  / /\ /\ /\ /\ /\ /\ /\ 
        \/      \/                \//_____/  \/ \/ \/ \/ \/ \/ \/""")
    gLine()
    sys.exit

def gHelp():
    clear()
    gLine()
    p2("""
  ___ ___        .__              _____                       
 /   |   \  ____ |  | ______     /     \   ____   ____  __ __ 
/    ~    \/ __ \|  | \____ \   /  \ /  \_/ __ \ /    \|  |  \
\    Y    |  ___/|  |_|  |_> > /    Y    \  ___/|   |  \  |  /
 \___|_  / \___  >____/   __/  \____|__  /\___  >___|  /____/ 
       \/      \/     |__|             \/     \/     \/    """)
    gLine()
    print("Welcome to the help menu!")
    print("1. Go Back")
    options = ["1"]

    PI()
    if PI == 1:
        (back())

def gNorthernLights():
    gLine()
    ps2("""  ` : | | | |:  ||  :     `  :  |  |+|: | : : :|   .        `              
      ` : | :|  ||  |:  :    `  |  | :| : | : |:   |  .                    :
         .' ':  ||  |:  |  '       ` || | : | |: : |   .  `           .   :.
                `'  ||  |  ' |   *    ` : | | :| |*|  :   :               :|
        *    *       `  |  : :  |  .      ` ' :| | :| . : :         *   :.||
             .`            | |  |  : .:|       ` | || | : |: |          | ||
      '          .         + `  |  :  .: .         '| | : :| :    .   |:| ||
         .                 .    ` *|  || :       `    | | :| | :      |:| |
 .                .          .        || |.: *          | || : :     :|||
        .            .   . *    .   .  ` |||.  +        + '| |||  .  ||`
     .             *              .     +:`|!             . ||||  :.||`
 +                      .                ..!|*          . | :`||+ |||`
     .                         +      : |||`        .| :| | | |.| ||`     .
       *     +   '               +  :|| |`     :.+. || || | |:`|| `
                            .      .||` .    ..|| | |: '` `| | |`  +
  .       +++                      ||        !|!: `       :| |
              +         .      .    | .      `|||.:      .||    .      .    `
          '                           `|.   .  `:|||   + ||'     `
  __    +      *                         `'       `'|.    `:
"'  `---''''----....____,..^---`^``----.,.___          `.    `.  .    ____,.,-
    ___,--''''`---''   ^  ^ ^        ^       """'---,..___ __,..---'''
"'                               ^                         ``--..,__ """)
    gLine()
#Text Functions-----------------------------------------------------#

def ps(string):
    #This function allows the game to type like a real person 
    #PS is short for "Print Slow"
    typing_speed = 70
    count = 0
    space = False
    #This aspect of the function works with the autotext wrap
    #To make sure that it only wraps after full words, not 
    #midway through 
    for letter in string:
        if letter == " " or letter == "": 
            space = True
        else:
            space = False

        if count >= 50 and space == True:
            print('\n')
            count = 0      


        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(random.random()*10.0/typing_speed)

    print('')

def ps2(str):
    #This function is the same as PS1 but without the Text Wrapping 
    typing_speed = 600
    #Ask Mr. Ortiz how to make previous function based of line len.
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(random.random()*10.0/typing_speed)
    print('')


#Mechanics----------------------------------------------------------#

#Game Loop----------------------------------------------------------#

def titleScreen():
    gHeader()
    ps("1. Start")
    ps("2. Load")
    ps("3. Exit")
    ps("4. Help")
    options = ["1","2","3","4"]

    pI(options)

    if pI == 1:
        dream0()
        pCS = dream0()
    if pI == 2:
        load
    if PI == 3:
        gExit()
    if PI == 4:
        gHelp()

def dream0():
    clear()
    gNorthernLights()
    ps("[???] Your name my son..what do the mortals use to summon you?")
    pName = str(input("==> "))
    ps(pName + "? I'm just as amused by the lower realm's creativity, as their ability to destroy themselves.")
    ps("The void..she calls to you" + pName + "She favors you, just as her divinity does to me. You..shall be my avatar. It is time. Her prophecy shall be fullfilled. Awaken, my child!")
    time.sleep(3)
    clear()




#dream0()
titleScreen()

#Player Data--------------------------------------------------------#
pName = "Yorick"
pTrueName = "kliros"
pCS = titleScreen()
 #pCS stands for Player Current Scene 

Upvotes: 0

Views: 35

Answers (1)

J369
J369

Reputation: 477

There are several issues here:

if playerInput not in options or commands:

This will activate if playerInput is not in options, or if commands is defined. You meant to say that it should activate if playerInput is not in options AND playerInput is not in commands.

pI(options)

if pI == 1:
    dream0()
    pCS = dream0()
if pI == 2:
    load
if PI == 3:
    gExit()
if PI == 4:
    gHelp()

Here, you expect pI(options) to return some value, but you never save it. When you check pI == 1, you are checking if the function is equal to 1, which is nonsense. Additionally, pI returns a string, not a number. Instead, you should have the following:

playerInput = pI(options)

if playerInput == "1":
    dream0()
    pCS = dream0()
if playerInput == "2":
    load
if playerInput == "3":
    gExit()
if playerInput == "4":
    gHelp()

Upvotes: 2

Related Questions