I am trying to simply get the value out of my class using a simple function with a return value, I'm sure its a trivial error, but im pretty new to python
I have a simply class set up like this:
class score():
#initialize the score info 
    def __init__(self):
        self.score = 0
        self.num_enemies = 5
        self.num_lives = 3
    # Score Info
    def setScore(num):
        self.score = num
    # Enemy Info
    def getEnemies():
        return self.num_enemies
    # Lives Info
    def getLives():
        return self.getLives
etc.....
Than I create an instance of the class as such:
scoreObj = score()
for enemies in range(0, scoreObj.getEnemies):
    enemy_sprite.add(enemy())  
I get the error saying that an integer is expected, but it got an instancemethod
What is the correct way to get this information?
Thanks!
scoreObj.getEnemies is a reference to the method.  If you want to call it you need parentheses: scoreObj.getEnemies().
You should think about why you are using a method for this instead of just reading self.num_enemies directly.  There is no need for trivial getter/setter methods like this in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With