class hero():
def __init__(self, name="Jimmy", prof="Warrior", weapon="Sword"):
"""Constructor for hero"""
self.name = name
self.prof = prof
self.weapon = weapon
self.herodict = {
"Name": self.name,
"Class": self.prof,
"Weapon": self.weapon
}
self.herotext = {
"Welcome": "Greetings, hero. What is thine name? ",
"AskClass": "A fine name %s. What is thine class? " % self.herodict['Name'],
"AskWeapon": "A %s ? What shalt thy weapon be? " % self.herodict['Class'],
}
def setHeroDict(self, textkey, herokey):
n = raw_input(self.herotext[textkey])
self.herodict[herokey] = n
print self.herodict[herokey]
h = hero("Tommy", "Mage", "Staff")
h.setHeroDict("Welcome", "Name")
h.setHeroDict("AskClass", "Class")
Alright so, I asked this once before here and a smart fellow told me to try using lambdas. I tried it and it worked. Great! However my question here is a bit different. As I stated there, Im pretty new at this, and have a good deal of holes in my knowledge that im trying to fill. Basically.. how do I do this better without having to use lambdas (or do people usually use lambdas for this?)
What im trying to do:
- Have a hero class with some variables that have some defaults attached to them.
- I then want to use a definition that can go and use my
herotext
to use one of the values to ask a question. - The user then answers the question, and that defenition goes and
changes the appropriate value in
herodict
Problem im trying to get passed:
In my herotext
I have a value that itself points to a key in herodict
. As explained in the link, this I have learned is due to the herodict
being initialized to the default values along with herotext
before a user can provide input. So it prints out the default (Tommy in this case) name instead of the new user input name in the "AskClass" self.herodict['Name']
value.
How do I fix this? I dont mind if I have to make another file or whatever, I just want to know what is a more logical way of doing this sort of thing? Ive been stuck on this all day and my mind is friend. I know it may be simple to a lot of you and Im hoping you will share your knowledge.
Thanks