Picking Function from Manual crashes


I got a problem with this example picking function from the manual. If i click on the node that is ‘clickable’ alias tagged, it works properly. But when i click on empty space it asserts with the following error:

Here is the function, its a 1:1 copy of the function myFunction from the manual:

    def mouse1Clicked(self):
        mpos = base.mouseWatcherNode.getMouse()
        self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
        if self.collisionHandler.getNumEntries > 0:
            self.collisionHandler.sortEntries() # Damit das vorderste als erstes erkannt wird
            pickedObj = self.collisionHandler.getEntry(0).getIntoNodePath()
            pickedObj = pickedObj.findNetTag('pickableTag')
            if not pickedObj.isEmpty():
                print "clicked"


There is a typo. Replace this line:

        if self.collisionHandler.getNumEntries > 0:

With this:

        if self.collisionHandler.getNumEntries() > 0:

Without the parantheses, you are testing whether the function itself is greater than zero, instead of testing whether the return value of the function is greater than zero. As it happens, all functions (as well as most other non-integer objects) are greater than zero.


Ah, thanks. Didnt see that and it makes perfectly sense that a method-reference isnt 0.