Collision Problen

I have a Collision Problem.

I have this actor class “Item” and it should lie on the ground of uneven terrain, like in roaming ralph, but the Z point stays on 0

Heres a bit of code:

class Item(Actor):
    def __init__(self):
        self.cTrav = CollisionTraverser()
        pandaGroundRay = CollisionRay()
        pandaGroundRay.setOrigin(0,0,10000)
        pandaGroundRay.setDirection(0,0,-1)
        pandaGroundCol = CollisionNode('pandaRay')
        pandaGroundCol.addSolid(pandaGroundRay)
        pandaGroundCol.setFromCollideMask(BitMask32.bit(0))
        pandaGroundCol.setIntoCollideMask(BitMask32.allOff())
        pandaGroundColNp = self.attachNewNode(pandaGroundCol)
        self.pandaGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(pandaGroundColNp, self.pandaGroundHandler)

    def setHeight(self, env=None):
        entries = []
        self.cTrav.traverse(render)
            


        for e in xrange(self.pandaGroundHandler.getNumEntries()):
            entry = self.pandaGroundHandler.getEntry(e)
            entries.append(entry)

        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                        x.getSurfacePoint(render).getZ()))
        if (len(entries)>0):
                
            self.setZ(entries[0].getSurfacePoint(render).getZ())
            self.pos = self.getPos()
        else: 
            print "ERROR IN Item.setHeight"

It always prints out that error, and I dont know why. Have I forgot a call? Why isnt my code working?

If you run setHeight() as a task, returning None makes it executed only once.

I havnt set it at a task, and when it would be called only one time, it would be ok, because it doesnt move

I really can’t get this line of code:

entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                        x.getSurfacePoint(render).getZ())) 

could you explain me its purpose?