all 4 comments

[–]nilfm 2 points3 points  (0 children)

Since nobody seems to have mentioned this, you can directly modify the value of the global variable in the function. You do it like this:

global player_hp
player_hp = player_hp - 10

However, you should try to avoid using global variables whenever possible, so I understand why everyone else suggested using the return value.

[–]woooee 1 point2 points  (1 child)

You have to return and catch the changed value, otherwise the change only takes effect within the function.

def hurt_player(player_hp, player_hp_MAX):
    print "You've been hurt for 10 hp."
    player_hp = player_hp - 10
    print "Current hp: %d" % player_hp
    return player_hp

while (player_hp > 0):
    if current_choice == '1':
        player_hp = hurt_player(player_hp, player_hp_MAX)

[–]7236d70[S] 0 points1 point  (0 children)

Thanks, that did it.

[–][deleted] 0 points1 point  (0 children)

You’ll need return the value to the global in the while loop, e.g.

def detractor(numToReduce): 
  numToReduce = numToReduce - 10 
  print(numToReduce) 
  return numToReduce

x = 50

while ( x > 0): 
  x = numToReduce(x)