I have an orc object, and a radar object that needs to keep track of orcs it can see. I'm keeping track of orcs using a list, but when I try to pull an orc (or data about it) out of the list I get an attribute error.
The exact error is:
AttributeError: type object 'orc' has no attribute 'name'
Here's the radar class
from source.orc import orc
class radar(object):
"""
radar Class
"""
def __init__(self, maxOrcs=25):
self.maxOrcs = maxOrcs
self.numOrcs = 0
self.orcList = [orc]
logger.info('Radar created!')
def addOrc(self, orc=None):
self.numOrcs = self.numOrcs +1
self.orcList.append(orc)
logger.info('Orc added to battlefield!')
def distance(self, name):
retVal = None
logger.debug('calculating distance')
for orc in self.orcList:
if name in orc.name:
retVal = ( (500 - orc.locx) + (500 - orc.locy) )
break
return retVal
If it helps at all here's the orc class
class orc(object): #Orc class
def __init__(self, name='Krusk', locx=1, locy=1, speed=1):
#set name
if(len(name) < 20):
self.name = name
else:
self.name = 'Krusk'
logger.warning('Default name used')
#set x coord
if(isinstance(locx, int) != True):
self.locx = 1
logger.warning('x coordinate set to 1, Not an int')
elif(locx < 1):
self.locx = 1
logger.warning('x coordinate set to 1, passed value to low')
elif(locx > 1000):
self.locx = 1000
logger.warning('x coordinate set to 1000, passed value to high')
else:
self.locx = locx
#set y coord
if(isinstance(locy, int) != True):
self.locy = 1
logger.warning('x coordinate set to 1, Not an int')
elif(locy < 1):
self.locy = 1
logger.warning('y coordinate set to 1, passed value to low')
elif(locy > 1000):
self.locy = 1000
logger.warning('x coordinate set to 1000, passed value to high')
else:
self.locy = locy
#set speed
if(speed < 0):
self.speed = 0
logger.warning('speed set to 0, passed value cannot be negative')
else:
self.speed = speed
logger.info('Orc created!')
self.orcList = [orc()]orc().