Stormy
Stormy

Reputation: 33

Type Error Python

I am currently working on a game and I tried to make an image move and I keep getting this error right here

TypeError: unbound method put_here() must be called with create_entity instance as first argument (got int instance instead)

Here is the code for the PlayerEntity.py file the I made.

class create_entity:
    def __init__(self, image, name, armor, skills, weapons):
        self.entity_image = image
        self.entity_name = name
        self.entity_armor = armor
        self.entity_skills = skills
        self.entity_weapons = weapons

    def put_here(self,x,y):
        screen.blit(self.entity_image, (x,y))

Now here is the main Game file that I was testing this in

if __name__ == '__main__':
    import PlayerEntity as p_entity
    p_entity.create_entity('test_img.png', 'Default', [], [], [])
    p_entity.create_entity.put_here(300,300)

Upvotes: 1

Views: 65

Answers (1)

Nir Alfasi
Nir Alfasi

Reputation: 53535

You should save the instantiated object into a variable and use it to call its function:

entity = p_entity.create_entity('test_img.png', 'Default', [], [], [])
entity.put_here(300,300)

This code assumes that import PlayerEntity as p_entity returns a module p_entity that contains the class create_entity (bad name for a class - by the way)

Upvotes: 1

Related Questions