I created a class that has 4 arguments given when the object is created and two further attributes that are defined inside the class itself.
Code: Select all
class NPerson(object):
def __init__(self, s_forename, s_surname, s_location, i_love):
self.s_forename = s_forename
self.s_surname = s_surname
self.s_location = s_location
self.i_love = i_love
@property
def s_name(self):
return "{} {}".format(self.s_forename, self.surname)
@property
def s_avatar(self):
s_mood = "_neutral.png"
if 10 >= self.i_love < 20:
s_mood = "_neutral.png"
elif 10 < self.i_love >= 0:
s_mood = "_unhappy.png"
elif 20 >= self.i_love:
s_mood = "_happy.png"
return "ui/avatars/" + self.s_forename + "/" + self.s_forename + s_mood
#object of the Class NPerson
l_npc = []
l_npc.append(NPerson("Eileen", "Smith", "Library", 10))
Code: Select all
screen scr_character():
$ i_charPos_x = 200
for q in l_npc:
if q.s_location == s_location:
imagebutton:
hover q.s_avatar
idle q.s_avatar
xpos i_charPos_x
yalign 1.0
focus_mask True
action NullAction()
AttributeError: 'NPerson' object has no attribute 's_avatar'
I have no clue where I dropped the ball here. And the more I look for it, the less I understand is. Maybe someone with fresh eyes could check what it is?