class - Python/Pygame: subclass not finding variable -


probably not right title i've no idea how else formulate it.
i'm trying calculate stats based on flexible values, hp & mp , return values can printed on screen. i've tried making separate class stats , calling on that, changing self.hp in both stats when it's called upon nothing seems work , can't figure out how fix it.
know it's lot of code have @ it, please?

e1: after copying right code here (i'm idiot -_-') , changing hp self.hp program goes bananas... literally runs death.

import formulae formulae import *  characters = {"1":battle_maiden("hibikime")} enemies = {"a":enemy("enemy")}  while characters["1"].alive , enemies["a"].alive:     print     characterskey, in sorted(characters.keys()):         print(characters[characterskey]) 

code that's in formulae.py:

class character(object):     def __init__(self, name):         self.name = name         self.alive = true         self.hit = 10         self.dodge = 0         self.lv = 1      def __str__(self):         if self.alive:             return "%s (%i hp, %i mp)" % (self.name, self.hp, self.mp)         else:             return "%s (dead)" % self.name      def attack(self, enemy):         print(self.name, "attacks", enemy.name)         enemy.hit()      def hit(self):         self.hp -= self.atk         print(self.name, "is hit! (",self.atk,")")         if self.hp <= 0:             self.die()      def die(self):         self.alive = false         print(self.name, "died.")   class enemy(object):     def __init__(self, name):         self.name = name         self.alive = true         self.hp = 100         self.mp = 20         self.m_atk = 10         self.atk = 30         self.def = 5         self.m_def = 5         self.hit = 10         self.dodge = 0      def __str__(self):         if self.alive:             return "%s (%i hp, %i mp)" % (self.name, self.hp, self.mp)         else:             return "%s (dead)" % self.name      def attack(self, enemy):         print(self.name, "attacks", enemy.name)         enemy.hit()      def hit(self):         self.hp -= self.atk         print(self.name, "is hit! (",self.atk,")")         if self.hp <= 0:             self.die()      def die(self):         self.alive = false         print(self.name, "died.")   ##subclasses characters##  class battle_maiden(character):     def __init__(self, name):         super(battle_maiden, self).__init__(self)         classhp = 80         classmp = 5         vitality = 10         wisdom = 3         intelligence = 2         strength = 15         defense = 5         dexterity = 15         agility = 2          self.hp = (classhp + (self.lv*5) + (vitality *(self.lv *0.3)))         self.mp = (classmp + (self.lv*2) + (wisdom *(self.lv *0.2)))         atk = (strength * (self.lv*0.2))         m_atk = (intelligence * (self.lv*0.2))         def = (defense + (self.lv*1.5) + (defense*0.1))         m_def = (intelligence + (self.lv*1.5) + (intelligence*0.1)) 

the error i'm getting:
return "%s (%i hp, %i mp)" % (self.name, self.hp, self.mp)
runtimeerror: maximum recursion depth exceeded

first first, double importing naughty don't ;)

and fixing pretty simple, have replace replace

super(battle_maiden, self).__init__(self) 

with

character.__init__(self, name) 

as of why, try find out on own. if can't in 30 minutes, ask in comment , spoil ;)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -