Yes. There is a specific problem. It's kind of hard for me to know exactly what code to post (I'm so lost It's really hard to be sure). Also, my code is really ugly. The code is based on the complete roguelike tutorial code, but I've tried to come up with my own way to do as many things as I can, which is probably why it doesn't work now. Anyway, maybe this is a decent start.
the monster AI module is supposed to be called after the player has moved, and this is my attempt to do that:
def monster_act():
if player_action != False:
if game_state == 'playing':
for object in objects:
if object.ai == Hostile_AI:
if object.alive:
object.Hostile_AI.take_turn()
Problem is, I get an exception saying that my object class (of which monsters are a member), doesn't have an attribute "Hostile AI"
Well, here is my object class template:
class Object:
def __init__(self, x, y, char, name, color, ai = None, item = None, status = None, equipment = None, inventory = None, alive = True, blocks = False):
self.x = x
self.y = y
self.char = char
self.name = name
self.color = color
self.ai = ai
if self.ai:
self.ai.owner = self
self.item = item
if self.item:
self.item.owner = self
self.status = status
if self.status:
self.status.owner = self
self.equipment = equipment
if self.equipment:
self.equipment.owner = self
self.inventory = inventory
self.alive = alive
self.blocks = blocks
There's more code for object, but this is already a ton, so I won't post it unless you tell me to.
And here's a specific instance of object:
monster = Object(x, y, 'R', 'Razor head ' + str(razorhead_no), libtcod.black, ai = Hostile_AI,
status = razorhead_status, alive = True, blocks = True)
razorhead_no = razorhead_no + 1
Hostile ai is there! I don't see what the problem is.
The whole idea behind my question was that I thought if I knew how python handled attributes/variables, that I would be able to figure out myself what went wrong.
*Edited for clarity