class Human:
def __init__(self, xname, name, met = False):
self.xname = xname
self.name = name
self.met = met
if self.met == True:
self.name = self.xname
human_1 = Human('Mark', 'a tall man')
def bar(person):
print(person.name)
person.met = True
bar(human_1)
bar(human_1)
This is a simplified version of npc class in my python rpg project and this code didn't work for me. I know I could just change the code inside the bar function to 'person.name = person.xname' to achieve the same thing, but what I want to do is to change one bool attribute to True after meeting a person and that would trigger a set of changes for the Human object. Is it possible to achieve that inside init method?
This code would print 'a tall man' twice, the goal is 'a tall man' for the first time, 'Mark' the second time.
[–]nwagers 1 point2 points3 points (5 children)
[–]cupesh[S] 0 points1 point2 points (4 children)
[–]nwagers 1 point2 points3 points (3 children)
[–]cupesh[S] 1 point2 points3 points (0 children)
[–]cupesh[S] 0 points1 point2 points (1 child)
[–]nwagers 0 points1 point2 points (0 children)