This is the code.
#When I try to make the variable ‘enemy’ save globally, it says ‘Variable referenced before assignment.’, or something along those lines. How do I fix this?
#If you are going to suggest to make it all one function, I tried and it didn't work out. I am doing this so I can keep repeating the turn function until the player enters a vaild command.
#Player and enemy stat blocks. Order of stat blocks is: Health, Weapon, Weapon damage, Armor, and Armor type.
PC = [50, 'shortsword', 20, 'chain mail', 10]
goblin = [30, 'dagger', 15, 'leather', 5]
# Function for a single turn.
def turn(enemy):
turn1 = input('Your turn. What would you like to do? ').lower()
if turn1 != 'attack':
print('Invalid command.')
turn(enemy)
elif turn == 'attack':
global enemy
enemy[0] = enemy[0] - PC[2]
# Function for the entirety of combat.
def combat(enemy):
while enemy[0] > 0:
turn1 = input('Your turn. What would you like to do?')
turn(enemy)
combat(goblin)