Very, very simple question here. How would I modify a variable through a function? I feel really dumb for asking this. Here's what I have:
enemyHealth = 100
def Attack():
enemyHealth -= 10
Apparently, enemyHealth is not defined.
I would expect that you wouldn't need to return anything. What am I doing wrong?
globalif you want to modify it within a function. See here. But realistically, this is rarely the best solution--you'd more likely want an instance of someEnemyclass, with its ownhealthattribute for you to modify. See this answer for an explanation/example.