Hey Guys

I have some code problem with my classes. Can anyone tell me what has happened?

class Location(object):
    def location(self, index, desc, lootvalue=0, loot_type=0):
        self.index = index
        self.desc = desc
        self.lootvalue = lootvalue
        self.loot_type = loot_type
        self.nuetralmobspawn = nuetral_mob_spawn
        self.passivemobspawn = passive_mob_spawn
        self.hostilemobspawn = hostile_mob_spawn

    def __repr__(self):
        text = "Location: %s" % self.desc
        text+= ", Index: %s" % self.index
        text+= ", lootvalue: %s" % self.lootvalue
        text+= ", loot_type: %s" % str(self.loot_type)
        return text

#Locations
woods = Location(1, "Woods")
river = Location(2, "River")
coast = Location(3, "Coast")
mountains = Location(4, "Mountains")
village = Location(5, "Village")
abandoned_shack = Location(6, "Abandoned Shack", random.randint(0, 3),
                           (1, 2, 3, 4, 5))
upturned_cargo_carriage = Location(7, "Upturned cargo carriage",
                                   random.randint(0, 2), (2, 5))

print woods
print river
print coast
print mountains
print village
print abandoned_shack
print upturned_cargo_carriage

Location; Woods, Index; 1, lootvalue; 0, loot_type; 0
Location; River, Index; 2, lootvalue; 0, loot_type; 0
Location; Coast, Index; 3, lootvalue; 0, loot_type; 0
Location; Mountains, Index; 4, lootvalue; 0, loot_type; 0
Location; Village, Index; 5, lootvalue; 0, loot_type; 0
Location; Abandoned_Shack, Index; 6, lootvalue; 1, loot_type; (1, 2, 3, 4, 5)
Location; Upturned_Cargo_Carriage, Index; 7, lootvalue; 1, loot_type; (2, 5)

Thanks
Andrew!

Try this:

import random

class Location(object):
    def __init__(self, index, desc, lootvalue=0, loot_type=0):
        self.index = index
        self.desc = desc
        self.lootvalue = lootvalue
        self.loot_type = loot_type
        #self.nuetralmobspawn = nuetral_mob_spawn
        #self.passivemobspawn = passive_mob_spawn
        #self.hostilemobspawn = hostile_mob_spawn

    def __repr__(self):
        text = "Location: %s" % self.desc
        text += ", Index: %s" % self.index
        text += ", lootvalue: %s" % self.lootvalue
        text += ", loot_type: %s" % str(self.loot_type)
        return text


#Locations
woods = Location(1, "Woods")
river = Location(2, "River")
coast = Location(3, "Coast")
mountains = Location(4, "Mountains")
village = Location(5, "Village")
abandoned_shack = Location(6, "Abandoned Shack", random.randint(0, 3),
                           (1, 2, 3, 4, 5))
upturned_cargo_carriage = Location(7, "Upturned cargo carriage",
                                   random.randint(0, 2), (2, 5))

print woods
print river
print coast
print mountains
print village
print abandoned_shack
print upturned_cargo_carriage

'''result -->
Location: Woods, Index: 1, lootvalue: 0, loot_type: 0
Location: River, Index: 2, lootvalue: 0, loot_type: 0
Location: Coast, Index: 3, lootvalue: 0, loot_type: 0
Location: Mountains, Index: 4, lootvalue: 0, loot_type: 0
Location: Village, Index: 5, lootvalue: 0, loot_type: 0
Location: Abandoned Shack, Index: 6, lootvalue: 0, loot_type: (1, 2, 3, 4, 5)
Location: Upturned cargo carriage, Index: 7, lootvalue: 0, loot_type: (2, 5)
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.