Hey, I'm coding a text based game and stumbled upon a problem when debugging the first demo.
I receive this error when running the game:
line 97
SOLVED: False,
^
SyntaxError: invalid syntax
I have no idea what is causing this problem.
The only lines (I think) you have to look into are:
74-81
85-88
94-101 (this line is copy pasted all the way to line 181, but changed strings)
I'm also having problems with l"valid.jobs" at the lines:
274-280
315-230
The error message said something about "valid" not being an existing variable
This is my entire code:
I receive this error when running the game:
line 97
SOLVED: False,
^
SyntaxError: invalid syntax
I have no idea what is causing this problem.
The only lines (I think) you have to look into are:
74-81
85-88
94-101 (this line is copy pasted all the way to line 181, but changed strings)
I'm also having problems with l"valid.jobs" at the lines:
274-280
315-230
The error message said something about "valid" not being an existing variable
This is my entire code:
import cmd import textwrap import sys import os import time import random screen_width = 100 ##### Player Setup ##### class player(): def __init__(self): self.name = '' self.job = '' self.hp = 0 self.mp = 0 self.status_effects = [] self.location = 'a1' self.game_over = False myPlayer = player ##### Title Screen ##### def title_screen_options(): option = input('>') if option.lower() == ('play'): setup_game() elif option.lower() == ('help'): help_menu() elif option.lower() == ('quit'): sys.exit() #### Try calling the title_screen_options after Invalid Command while option.lower() not in ['play', 'help', 'quit']: print('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') title_screen_options() def help_menu(): print('############################') print('# How to play #') print('############################') print("-To Move: enter 'up', 'down',") print(" 'left', or 'right\n") print("-To Inspect: enter 'inspect'\n") print("-To Quit: enter 'quit'\n") print(" 'Back' ") title_screen_options ################################################# Add "Back" option ##################################### #### Map #### #a1 #Player starts at a1 #------------------ #l x l l l a3 #------------------ #l l l l b3 #------------------ #l l l l c3 #------------------ ZONENAME: 'zonename' DESCRIPTION: 'description' EXAMINATION: 'examination' SOLVED: False UP: 'up' DOWN: 'down' LEFT: 'left' RIGHT: 'right' valid = True solved_places = {'a1': False, 'a2': False, 'a3': False, 'b1': False, 'b2': False, 'b3': False, 'c1': False, 'c2': False, 'c3': False, } zonemap = { 'a1': { ZONENAME: 'Desert', DESCRIPTION: 'Sun blazing, sand everywhere, Im in middle of a desert', EXAMINATION: 'In the distance, a hooded figure with green clothes, sitting on a red carpet hovering above the sand.' SOLVED: False, UP: '', DOWN: 'b1', LEFT: '', RIGHT:'a2', }, 'a2': { ZONENAME: 'Desert Mirage', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: '', DOWN: 'b2', LEFT: 'a1', RIGHT:'a3', }, 'a3': { ZONENAME: 'Desert Village', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: '', DOWN: 'b3', LEFT: 'a2', RIGHT:'', }, 'b1': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'a1', DOWN: 'c1', LEFT: '', RIGHT:'b2', }, 'b2': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'a2', DOWN: 'c2', LEFT: 'b1', RIGHT:'b3', }, 'b3': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'a3', DOWN: 'c3', LEFT: 'b2', RIGHT:'', }, 'c1': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'b1', DOWN: '', LEFT: '', RIGHT:'c2', }, 'c2': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'b2', DOWN: '', LEFT: 'c1', RIGHT:'c3', }, 'c3': { ZONENAME: '', DESCRIPTION: 'description', EXAMINATION: 'examine', SOLVED: False, UP: 'b2', DOWN: '', LEFT: 'c2', RIGHT:'', }, } ##### Game Interactivity ##### def print_location(): print('\n' + ('#' * (4 + len(myPlayer.location)))) print('# ' + myPlayer.location + ' #') print('#' + zonemap[myPlayer.location] [DESCRIPTION] + ' #') print('\n' + ('#' * (4 + len(myPlayer.location)))) def prompt(): 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 command, try another.\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 go?\n' dest = input(ask) if dest in ['up', 'north']: destination = ZONENAME[myPlayer.location] [UP] movement_handler(destination) if dest in ['down', 'south']: destination = ZONENAME[myPlayer.location] [DOWN] movement_handler(destination) if dest in ['left', 'west']: destination = ZONENAME[myPlayer.location] [LEFT] movement_handler(destination) if dest in ['right', 'east']: destination = ZONENAME[myPlayer.location] [RIGHT] 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 ZONENAME[myPlayer.location] [SOLVED]: print("It doesn't seem like there is anything noteworthy left here.\nMaybe I should look elsewhere.") else: print("There's something interessting with this place...") ##### Game Functionality ##### def setup_game(): os.system('cls') def main_game_loop(): while myPlayer.game_over is False: prompt() # here handle if puzzles has been solved, boss defeated, explored everything... #### Name Collection question1 = "Hello there, 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 = "player_name + huh...\nYes... I recognize that name but I do not remember where from...\n" for character in question2: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.05) ### Job Handling #### question3 = "Well then, tell me...\n Are you a mighty Warrior or a wize Wizard?\n" question3added = "(Warrior or Wizard)\n" for character in question3: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.05) for character in question3added: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.1) player_job = input('> ') valid.jobs = ['warrior', 'wizard'] if player_job.lower() in valid.job: myPlayer.job = player_job else: while player_job.lower not in valid.jobs: player_job = input('> ') if player_job.lower() in valid.jobs: myPlayer.job = player_job question4 = player_name + " the mighty " + player_job + " huh...\n" #yes or no for character in question1: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.05) player_name = input('>') myPlayer.name = player_name speach1 = "Yes, I do not know why I have your name in my mind...\n" speach2 = "But that is not important right now,\n" speach3 = player_name + ', ' speach4 = "tell me... are you wize/strong enough to escape this illusion of mine?" # #tell me, are you STRONG/WIZE (depening on warr or wiz) for character in speach1: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.03) for character in speach2: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.05) for character in speach3: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.01) for character in speach4: sys.stdout.write(character) sys.stdout.flush() time.sleep(0.03) #### Class Stats if myPlayer.job == 'warrior': player_hp = 100 player_mp = 20 elif myPlayer.job == 'wizard': player_hp = 50 player_mp = 120 os.system('cls') print('############################') print('# Let the games begin #') print('############################') main_game_loop()Edit: I have one more question, how to I break up code into lines to make it easier to read while coding, right now it's in a single line in python and is hard to read. It looks like this
DESCRIPTION: 'As you continue walking in the desert, there is nothing but sand wherever you look.\nYou feel as if you are in middle of the desert, as far away from anything as possible.\nThirsty, warm, fatigued... you continue wandering through the desert.\n' #I want it to look like this: 'As you continue walking in the desert, there is nothing but sand wherever you look.\n You feel as if you are in middle of the desert, as far away from anything as possible.\n Thirsty, warm, fatigued... you continue wandering through the desert.\n'