Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: invalid syntax
#8
edit: Jesus christ I might actually be the most stupid person alive. The "prompt()" was not indented in the right way, and I fixed the problem. I actually took like 30 mins of my time to write this. I will leave this for you to read anyway.




Jesus christ man, thank you so much for helping me, I'm going to stick with the 2nd example for now (but keep the others in mid)as I don't want it to become too complicated.

I know I'm really pushing myself as a complete newbie to python, actually to coding in general. I've learned so much the first week of coding and I promest, one day, I'm going to become an indie game developer, and publish games on Steam or Gog or something like that (I'm only 18 so I pretty much got my whole life ahed of me (except the 1/5 I've already wasted)), and you are the person that helped me, when completely new to coding and really had no clue what code.

With that out of the way, I have another problem, yeyeye I know, your pretty much my "free" teacher, I don't even understand why you spend your time to help people on this forum. Am I drunk? Not that much actually.

Anyway, I'm coding my "main_game_loop"
I'm done with the intro ("Whats your name" and "class"). HOWEVER, after the intro is done, the last code ("prompt()") doesn't activate. Instead the loop, keeps looping as if "prompt()" is not in the "main_game_loop"



tl;dr
What I want Python to do is excecute "prompt()", which should print "What would you like to do? (and the rest of prompt aswell). However as stated before, Python acts if "prompt()" is outside the loop for some reason.

This is what my "main_game_loop" looks like at the moment:

def prompt():
    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 main_game_loop():
    while myPlayer.game_over is False:

##### INTRO #####
        question1 = "Hello there, what's your name?\n"
        for character in question1:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)
        player_name = input('>')
        myPlayer.name = player_name

        os.system('cls')                             # Clear

        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.01)

### Job Handling
        question3 = "Well then, tell me...\nAre you a mighty Warrior or a wize Wizard?\n"
        for character in question3:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)
        player_job = input('> ')
        if player_job.lower() in valid_jobs:
            myPlayer.job = player_job                                            
        else:
            while player_job.lower not in valid_jobs:

                os.system('cls')
                                                                                                # Fix stuck in loop
                print('Say again, I did not understand.')                                      # Fix print flush and time  https://stackoverflow.com/questions/9246076/how-to-print-one-character-at-a-time-on-one-line
                print('What are you? a Warrior or a Wizard?')
                print('##### This part is bugged, restart game #####')
                player_job = input('> ')
                if player_job.lower() in valid_jobs:
                    myPlayer.job = player_job

        os.system('cls')                         #Clear

        question4 = player_name + " the mighty " + player_job + " huh...\n"                                           #yes or no
        for character in question4:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)

        speach1 = "Yes, I do not know why I have your name in my mind...\n"
        for character in speach1:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)
        speach2 = "But that is not important right now...\n"
        for character in speach2:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)

        os.system('cls')                     #Clear

        speach3 = player_name + ', \n'
        for character in speach3:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)
        speach4 = "tell me... are you wize enough to escape this illusion of mine?\n"                          # #tell me, are you STRONG/WIZE    (depening on warr or wiz)
        for character in speach4:
            sys.stdout.write(character)
            sys.stdout.flush()
            time.sleep(0.01)
        input('>')
        os.system('cls')
        print("In the blink of an eye, you appear in a place you have never been, as if you were pulled into another dimension.\n")
    
    prompt()
#### Launch Game ####
os.system('cls')
title_screen()       # Tiles_screen() - 'play - main_game_loop -
Reply


Messages In This Thread
SyntaxError: invalid syntax - by Kanashi - Nov-22-2019, 10:58 PM
RE: SyntaxError: invalid syntax - by ichabod801 - Nov-22-2019, 11:02 PM
RE: SyntaxError: invalid syntax - by Kanashi - Nov-22-2019, 11:35 PM
RE: SyntaxError: invalid syntax - by ichabod801 - Nov-22-2019, 11:50 PM
RE: SyntaxError: invalid syntax - by Kanashi - Nov-23-2019, 04:48 AM
RE: SyntaxError: invalid syntax - by ichabod801 - Nov-23-2019, 03:13 PM
RE: SyntaxError: invalid syntax - by ichabod801 - Nov-23-2019, 03:27 PM
RE: SyntaxError: invalid syntax - by Kanashi - Nov-24-2019, 05:59 AM
RE: SyntaxError: invalid syntax - by ichabod801 - Nov-24-2019, 01:39 PM
RE: SyntaxError: invalid syntax - by Kanashi - Nov-24-2019, 08:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print(data) is suddenly invalid syntax db042190 6 3,724 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  SyntaxError: invalid syntax ?? korenron 15 10,365 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 17,513 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 3,536 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 4,490 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 5,868 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  [split] SyntaxError: invalid syntax Code_X 3 3,936 May-04-2021, 05:15 PM
Last Post: Yoriz
  Invalid syntax error - need help fixing calgk01 3 4,739 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Invalid syntax using conditionals if - else jperezqu 1 3,096 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  invalid syntax in line 5. Help Asadzangibaloch 2 3,368 Dec-10-2020, 04:26 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020