here is the code that I am having a problem with(simplified to make it clearer). It is for a text based game just to help learn things.
class Character(object):
def __init__(self):
self.level = 5
self.moveset = [None,None,None,None]
def movesetleveling(self):
if self.level > 4:
self.moveset[0] = Punch(self.level)
def punch(level):
damagedealt = random.randint(0,5)**level
return damagedealt
I would like to know how I can make self.moveset[0] = Punch() rather than being equal to the output of Punch() in this block of code. So that everytime i run it in a while loop it will re-evaluate the output of Punch() rather than evaluating Punch() once and assigning that to the 0th index of self.moveset[0].
moveset?self.movesetor do you want the first item inself.movesetto be a random punch value in each iteration of your loop?movesetwill be used to show a selection of player moves. they will select a move from the list which will then be evaluated to produce an integer value which will be a damagestat. this damagestat will affect a Foes health. I have created a while loop which does this over and over but each time it uses the same value forself.moveset[0]rather than getting a new value.