Blender collision sensor is triggered twice I have this script with the module collision which is called when the player collides with any of two cylinders in the scene, the module increments the counter in a text object that in a separate scene that overlays the main scene

import bge

scene = bge.logic.getCurrentScene()

dynamicText = scene.objects['Text']

def collision():
    dynamicText.text = str(int(dynamicText.text)+1)


This the logic behind the cylinders that triggers the collision and send the message to the text object to increment the counter.



This is the login in the the text object



The problem is that the counter is incremented twice per collision, and I don’t see an obvious way to filter the second time the module is called.

This is the blend file.
If I remember correctly, collision sensors fire twice by design.  Once when set True, and another when False.

This isn't a problem when connected to an And or Not controller (because they check) but in a script you'll have to do something like this:

def collision(cont):
    # Loops through all connected sensors and returns if one is False
    # Basically makes it work like an And conroller.
    for sens in cont.sensors:
        if not sens.positive:
            return
    ...