fork download
  1. #I'm making a battling system and am running into a problem. I need to get two variables that are in
  2. #the function encounter() and use them in the function battle() which is inside encounter()
  3. #if it wasn't inside of the function I could just use return and then make a variable equal
  4. #to the function but since it is inside the function that isn't working.
  5. #I need to get monster_hp and player_hp inside battle()
  6.  
  7. def encounter(): #battle system
  8. battling, monster_name = rand_mon() #which monster you battle (actually their stats)
  9. player_hp = player.stats.hp
  10. monster_hp = battling.hp
  11. return(player_hp, monster_hp)
  12. def battle():
  13. while monster_hp > 0 and player_hp > 0:
  14. damage_this_turn = math.floor((random.randint(1, 5) * (player.stats.attack - battling.defense) / 2)/random.randint(2,4)) #equation for dealing damage
  15. monster_damage_this_turn = math.floor((random.randint(1, 5) * (battling.attack - player.stats.defense) / 2)/random.randint(2,4))
  16. if damage_this_turn <= 0: #never deal 0 damage
  17. damage_this_turn = 1
  18.  
  19. print("You have dealt " + str(damage_this_turn) + " damage to the " + monster_name + " this turn. It has " + str(monster_hp - damage_this_turn) + "hp left.")
  20. monster_hp -= damage_this_turn
  21.  
  22. print("The monster has dealt " + str(monster_damage_this_turn) + " damage to you this turn. You have " + str(player_hp - monster_damage_this_turn) + "hp left.")
  23. player_hp -= monster_damage_this_turn
  24. battle()
  25. battle()
Success #stdin #stdout 0.03s 9984KB
stdin
Standard input is empty
stdout
Standard output is empty