cannot unpack non-iterable NoneType object -returning a tuple

  iterable-unpacking, python-3.x, tuples

I don’t yet understand why this python code doesn’t work; it’s part of a little game we are making.
The following function is part of a class:

def detectCollision(self,other):
    if(self.x < other.x + other.w and
    self.x + self.w > other.x and
    self.y < other.y + other.h and
    self.y + self.h > other.y):
        return (self,True)

Later I call this function from within a loop:

for coin in coins[:]:
    
    (player,collided) = bob.detectCollision(coin)    
    if collided:
        coins.remove(coin)

But I get an error when I run the code:
"cannot unpack non-iterable NoneType object".

My understanding from other posts is that this occurs when trying to populate a tuple with only one value or the function doesn’t return anything… but my function returns a tuple, so I am at a loss as to why it cannot be unpacked. I also tried removing the brackets around the tuple.

Can anyone please kindly suggest a remedy?

Thank you

Source: Python-3x Questions

LEAVE A COMMENT