this concatenated question asked earlier today ("list" object not callable, syntax error text-based rpg). dilemma resides in adding herb player's herb list.
self.herb = [] is starting herb list. function collectplants:
def collectplants(self): if self.state == 'normal': print"%s spends hour looking medicinal plants." % self.name if random.choice([0,1]): foundherb = random.choice(herb_dict) print "you find %s." % foundherb[0] self.herb.append(foundherb) print foundherb else: print"%s doesn't find useful." % self.name with foundherb being random choice. how add item list in neat way (currently prints herb name, "none") , allow having several of same herb?
here's herb class:
class herb: def __init__(self, name, effect): self.name = name self.effect = effect sample list of herbs (warning: immaturity):
herb_dict = [ ("aloe vera", player().health = player().health + 2), ("cannabis", player().state = 'high'), ("ergot", player().state = 'tripping') ]
use list.
self.herb = [] foundherb = 'something' self.herb.append(foundherb) self.herb.append('another thing') self.herb.append('more stuff') print 'you have: ' + ', '.join(self.herb) # have: something, thing, more stuff edit: found code foundherb in 1 of other questions (please post in question too!), is:
foundherb = random.choice(herb_dict) when @ herb_dict:
herb_dict = [ ("aloe vera", player().health == player().health + 2), ("cannabis", player().state == 'high'), ("ergot", player().state == 'tripping') ] - this wrong, use
=assignment.==testing equality. - you need use function in second item in these tuples.
don't add second item list. this:
self.herb.append(foundherb[0])
Comments
Post a Comment