-1

This code does run but it's not triggering the inner function playerAction() when the main_game_loop() is triggered.

-I've used the IntelliJ debugger and it shows the condition, while myPlayer.game_over is False:, as being False. (pic added) img link showing debugger stating the while condition as False

-I've also tried to run it in VS Code and got the same result of the inner function being skipped over.

Question: If the while condition is met, why is the Python code jumping past the inner function call?

import cmd
import textwrap
import sys  
import os
import time
import random

screen_width = 100


########################### PLAYER SET UP ############################
class player:
    def __init__(self):  
        self.name = ''  
        self.job = ''  
        self.hp = 0  
        self.mp = 0
        self.status_effects = []
        self.location = 'b2'
        self.game_over = 'False'


myPlayer = player()  # set up the function call in a variable


############################ TITLE SCREEN ############################

def title_screen_selections():
    option = input("> ")
    if option.lower() == "play":
        setup_game()  # placeholder until written
    elif option.lower() == "help":
        help_menu()
    elif option.lower() == "quit":
        sys.exit()
    while option.lower() not in ['play', 'help', 'quit']:
        print("please enter a valid command.")
        option = input("> ")
        if option.lower() == "play":
            setup_game()
        elif option.lower() == "help":
            help_menu()
        elif option.lower() == "quit":
            sys.exit()


def title_screen():
    os.system("cls")
    print("############################")
    print("# Welcome to the Text RPG! #")
    print("############################")
    print("#         - Play -         #")
    print("#         - Help -         #")
    print("#         - Quit -         #")
    print("# Copyright 2022 myoung.me #")
    title_screen_selections()


def help_menu():
    print("############################")
    print("# Welcome to the Help Menu! #")
    print("############################")
    print("# Use up, down, left, right to move #")
    print("# Type your commands to do them #")
    print("# Use 'look' to inspect something #")
    print("# Good luck and have fun! #")
    title_screen_selections()


############################ MAP ############################
''' VISUALIZE THE MAP
a1 a2... # PLAYER STARTS AT b2
-------------
|  |  |  |  |  a4
-------------
|  |  |  |  |  b4 ...
-------------
|  |  |  |  |
-------------
|  |  |  |  |
-------------
'''
ZONENAME = ''
DESCRIPTION = 'description'
EXAMINATION = 'examine'
SOLVED = False
UP = 'up', 'north'
DOWN = 'down', 'south'
LEFT = 'left', 'west'
RIGHT = 'right', 'east'

solved_places = {'a1': False, 'a2': False, 'a3': False, 'a4': False,
                 'b1': False, 'b2': False, 'b3': False, 'b4': False,
                 'c1': False, 'c2': False, 'c3': False, 'c4': False,
                 'd1': False, 'd2': False, 'd3': False, 'd4': False,
                 }

zonemap = {
    'a1': {
        ZONENAME: 'Town Market',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: '',
        DOWN: 'b1',
        LEFT: '',
        RIGHT: 'a2',
    },
    'a2': {
        ZONENAME: 'Town Entrance',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: '',
        DOWN: 'b2',
        LEFT: 'a1',
        RIGHT: 'a3',
    },
    'a3': {
        ZONENAME: 'Town Square',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: '',
        DOWN: 'b3',
        LEFT: 'a2',
        RIGHT: 'a4',
    },
    'a4': {
        ZONENAME: 'Town Hall',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: '',
        DOWN: 'b4',
        LEFT: 'a3',
        RIGHT: '',
    },
    'b1': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'a1',
        DOWN: 'c1',
        LEFT: '',
        RIGHT: 'b2',
    },
    'b2': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'a2',
        DOWN: 'c2',
        LEFT: 'b1',
        RIGHT: 'b3',
    },
    'b3': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'a3',
        DOWN: 'c3',
        LEFT: 'b2',
        RIGHT: 'b4',
    },
    'b4': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'a4',
        DOWN: 'c4',
        LEFT: 'b3',
        RIGHT: '',
    },
    'c1': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'b1',
        DOWN: 'd1',
        LEFT: '',
        RIGHT: 'c2',
    },
    'c2': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'b2',
        DOWN: 'd2',
        LEFT: 'c1',
        RIGHT: 'c3',
    },
    'c3': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'b3',
        DOWN: 'd3',
        LEFT: 'b2',
        RIGHT: 'c4',
    },
    'c4': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'b4',
        DOWN: 'd4',
        LEFT: 'c3',
        RIGHT: '',
    },
    'd1': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'c1',
        DOWN: '',
        LEFT: '',
        RIGHT: 'd2',
    },
    'd2': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'c2',
        DOWN: '',
        LEFT: 'd1',
        RIGHT: 'd3',
    },
    'd3': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'c3',
        DOWN: '',
        LEFT: 'd2',
        RIGHT: 'd4',
    },
    'd4': {
        ZONENAME: 'Home',
        DESCRIPTION: 'description',
        EXAMINATION: 'examine',
        SOLVED: False,
        UP: 'c4',
        DOWN: '',
        LEFT: 'd3',
        RIGHT: '',
    },
}


############################ GAME INTERACTIVITY ############################
def print_location():  # creating a fx to display location of the player
    print('\n' + ('#' * (4 + len(myPlayer.location))))  # creating a buffer of hashtags
    print('#' + myPlayer.location.upper() + '#')
    print('# ' + zonemap[myPlayer.position][DESCRIPTION] + ' #')
    print('\n' + ('#' * (4 + len(myPlayer.location))))


def playerAction():
    print('\n' + '==============================')
    print('what would you like to do?')
    action = input("> ")
    acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine', 'inspect', 'interact', 'look']
    while action.lower() not in acceptable_actions:
        print('unknown action, try again. \n')
        action = input("> ")
        if action.lower() == 'quit':
            sys.exit()
        elif action.lower() in ['move', 'go', 'travel', 'walk']:
            player_move(action.lower())
        elif action.lower() in ['examine', 'inspect', 'interact', 'look']:
            player_examine(action.lower())


def player_move(myaction):
    ask = 'where would you like to move to? \n'
    dest = input(ask)
    if dest in ['up', 'north']:
        destination = zonemap[myPlayer.location][UP]
        movement_handler(destination)
    elif dest in ['left', 'west']:
        destination = zonemap[myPlayer.location][LEFT]
        movement_handler(destination)
    elif dest in ['right', 'east']:
        destination = zonemap[myPlayer.location][RIGHT]
        movement_handler(destination)
    elif dest in ['down', 'south']:
        destination = zonemap[myPlayer.location][DOWN]
        movement_handler(destination)


def movement_handler(destination):
    print("\n" + "you have moved to the " + destination + ".")
    myPlayer.location = destination
    print_location()


def player_examine(action):
    if zonemap[myPlayer.location][SOLVED]:
        print("you have already exhausted this zone.")
    else:
        print("you can trigger a puzzle here")


############################ GAME FUNCTIONALITY ############################


def main_game_loop():
    while myPlayer.game_over is False:
        playerAction()


def setup_game(self=None):
    os.system('cls')

    # can duplicate these 'question' codeBlocks
    question1 = "Hello, what's your name? \n"  
    for character in question1:  
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)
    player_name = input("> ")
    myPlayer.name = player_name

    question2 = "Hello, " + player_name + ". What role do you want to play? \n"  # getting player info from user for class/job
    question2added = "You can play as a warrior, priest, or mage)\n"
    for character in question2:  # display each of the question characters at a slow pace
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)
    for character in question2added:  
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.01)
    player_job = input("> ")
    valid_jobs = ['warrior', 'mage', 'priest']
    if player_job.lower() in valid_jobs:
        myPlayer.job = player_job
        print("You are now a " + player_job + "!\n")
    while player_job.lower() not in valid_jobs:
        player_job = input("> ")
        if player_job.lower() in valid_jobs:
            myPlayer.job = player_job
            print("You are now a " + player_job + "!\n")

    if myPlayer.job is 'warrior':
        self.hp = 120
        self.mp = 20
    elif myPlayer.job is 'mage':
        self.hp = 40
        self.mp = 120
    elif myPlayer.job is 'priest':
        self.hp = 60
        self.mp = 60

    statement1 = "Welcome, " + player_name + " the " + player_job + "!\n"  # statement made with player info from user for name and role
    for character in statement1:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)

    speech1 = "welcome to this fantasy world!\n"
    speech2 = "I hope it greets you well!\n"
    speech3 = "Just make sure you don't get too lost...\n"
    speech4 = "Hehehehe\n"
    for character in speech1:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.03)
    for character in speech2:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.03)
    for character in speech3:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)
    for character in speech4:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)

    os.system('cls')
    print("######################")
    print("#  Let's start now!  #")
    print("######################")
    main_game_loop()


####################### KICK OFF THE METHOD SEQUENCE #####################

title_screen()

1 Answers1

0

Thank you for the responses...and thank you Divakar Patil.

I had made the value of the game_over property in the Player class into a string of 'False' when it should have been a boolean of False.

I will also further research giving a 'minimal reproducible answer' here.

Thank you for the point in the right direction.