Code help (RPG GAME)

I need help making my fight menu work. I’m trying to make it so if you use an item or use a weapon, you deal damage and get sent back to the fight screen, if that makes sense. I also want to be able to have a back option that sends you back to the screen where you select what you do. Also, when in battle mode, when i try to press back after dealing damage, it gives me an error.

import random
    enemy = random.choice(enemy_options)
    print("An enemy appears: {}".format(enemy))
    battle_choice = input("What would you like to do?\n1. Fight\n2. Use Item\n3. Defend\n4. Run\n5. Hide\n  ")
    if battle_choice == "4":
      print("You run away and escape.")
      continue
    if battle_choice == "1":
      fight_choice = input("What attack item would you like to use?\n1. Wooden Stick\n2. Back\n")
      if fight_choice == "2":
        continue
      if fight_choice == "1":
        print("The stick did 10 damage!")
        fight_choice = input("What attack item would you like to use?\n1. Wooden Stick\n2. Back\n")
    if battle_choice == "2":
      item_choice = input("What special item would you like to use?\n1. Potion\n")
      if item_choice == "1":
        print("You are already at full hp!")
        battle_choice = input("What would you like to do?\n1. Fight\n2. Use Item\n3. Defend\n4. Run\n5. Hide\n  ")

Game code

Hi @ayoayosksk!

Please send a link to your Repl so we can help you easily.

1 Like

Is the codes in a loop such as while or for
If not, continue will NOT work and error will be raised
Or if it is, please tell us what the error is, with the traceback if possible

To have it deal damage, you can just put the code into a while loop, and every time to player chooses to attack you can subtract the dmg from the enemy’s health.

As everybody above wrote, please share the repl or a larger part of the code as this needs to be in a loop. Furthermore, please use if elif else, as this will make for ammeter code everytime you have excluding choices.
As alternative you can also consider the new match/case construct.

Btw you can also ask somebody in the forum to join in to help you here and there in your project.

3 Likes