0
def Act(enemy, pokemon, enemyHP, enemyType):
  num = round(random.uniform(0.95, 1.75), 2)
  print(MoveList)
  Move1 = input("Choose your attack! Input a number from 1-4, depending on the order of your moves. Input 5 to view everyone's stats! \n")
  if Move1 == "1":
    Move1 = str(MoveList[0])
    attacked = True
    dmg = 10 * num
    Move1 = MoveList[0]
    print(pokemon + " used " + Move1 + "! \n")
    enemyHP -= dmg
    print("It dealt " + str(dmg) + " damage to " + enemy + "! \n")
    print(enemy + " is now at " + str(enemyHP) + " HP!")
    return enemyHP

while battling == true:
    Act(RivalPKMN, starter, RivalHP, RivalType)

This function takes an input from the player, does a move, and deducts HP from the function parameter enemyHP (similar to Pokemon). However, after doing an input again, the enemyHP value does not update to what it was after the first move.

I tried using return statements but I'm not really sure what or where the problem even is.

Here's an example of how it looks:

Litten used Scratch!

It dealt 10.5 damage to Quaxly!

Quaxly's HP is now 44.5!

The second time I run the function it inputs the exact same thing without updating the HP value to what it was after the first move was done.

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

-3

This is a simple beginner mistake. just add global [variable name] at the start of the function and it should work.

Neoro
  • 7
  • 3
  • 1
    They return the value, so the proper solution is to assign it to the variable in the caller. – Barmar Feb 08 '23 at 17:12
  • 2
    (Ab)[using globals](https://stackoverflow.com/questions/19158339/why-are-global-variables-evil) is also a beginner mistake. I have seen courses that insist in teaching this, I can't understand why. – Ignatius Reilly Feb 08 '23 at 17:22