So I'm testing out some mechanics for a text-based game I was going to make. If the player has armour it would halve the damage they take and if not they would take full damage. The problem I'm having is that whenever I try to run the functions twice, it resets the health because it has been hardcoded. So I'm wondering how can I get the function to overwrite the health variable after it runs each time?
Here is the code:
import random
inventory = ["Armour","Sword","Healing Potion"]
health=100
def randDmg():
dealtDamage = random.randint(1,10)
print("You have taken "+str(dealtDamage)+" damage.")
return dealtDamage
def dmgCheck(damage, health):
if "Armour" in inventory:
damage = damage/2
else:
damage = damage
health-=damage
return health
print("Your new health is "+str(dmgCheck(randDmg(), health)))