0

I want to make it so that the user can eventually choose what attack they want to perform but for now, I'm trying to sort out 'attack'. I'm relatively new so any advice would be greatly appreciated. Thanks.

import random
print("Welcome to my game!")


def attack():
    attack = random.randint(10,20)
    magic = random.randint(5,30)
    run = 999
    user_choice = input("enter what you will do!: ")
    print('''A T T A C K :
M A G I C :
R U N :
             ''')
               
def goblin_attack():
    gob_attack = random.randint(5,10)
    
spaces = 50
def goblin():
    dead = False
    enemy_health = 20
    user_health = 100
    print("I am a goblin and I have come to slay you!")
    attack()
    while dead == False:
        if user_choice == 'attack':
            enemy_health = enemy_health - attack
            goblin_attack()
            user_health = user_health - gob_attack
        damage_dealt = random.randint(5,30)
        if enemy_health <= 0:
            print("aghhhhhhh")
            print("You defeated the goblin. Good job!")
            dead = True
            break

def dice_roll():
    while True:
        dice = input("press enter on your keyboard to roll the dice!: ")
        rolled_dice = random.randint(1,6)
        print("you rolled:",rolled_dice,"spaces")
        spaces_moved = 0
        spaces_moved = spaces_moved + rolled_dice
        monster_gen = random.randint(1,3)
        if monster_gen == 1:
            goblin()



dice_roll()
Danny_Fall
  • 29
  • 1
  • 3
  • 2
    You define `user_choice` in a different function. Each function has its own scope. You need to `return user_choice` inside of `attack`, then save that into a variable inside of `goblin`. – 0x5453 May 17 '21 at 20:05
  • https://stackoverflow.com/questions/291978/short-description-of-the-scoping-rules – Pranav Hosangadi May 17 '21 at 20:05
  • User_choice is defined in the attack function. so its scope means its only visable there. – Chris Doyle May 17 '21 at 20:05
  • Put `return user_choice` at the end of `attack()`, add `user_choice` to the parameter list of `goblin`, and then you can do `goblin(attack())` to pass the variable from one function to the other. – Samwise May 17 '21 at 20:07

0 Answers0