I am working on a very simple text based adventure game. I have been able to do the basics where the player can move from room to room. To enhance the game I wanted a simple combat system but I am having trouble implementing a system which will keep the players health score. I have provided a sample of how the code is at the moment and added comments.
def update_score(x): #after the player has a combat round the variable 'a'is updated with remianing hit points
a = []
a.append(x)
def hit_points(): #when the player is in combat and takes a hit, 2 points are deducted and it is passed to the updated score function
y -= 2
updated_score(y)
def Continue():
#how can i then reference the updated score in another function. If the player goes into another battle, the remaining battle points will have to be used and deducted from
I have only just started getting to grips with functions and would like to know if it is possible to pass the updated values from the updated_score function to other functions or when the hit point function is called again.
I am trying to avoid using Global variables.
Any help much appreciatted
returnthe values you need outside the function and to pass the values you need to use in other functions as arguments to those functions.