2D Filter deactivation script?

I have a script setup in my game, that activates a radial blur filter when “R” is pressed… I have it setup to deactivate the filter when “R” is released but it wont work.

import bge


def main():
    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    sens = cont.sensors['sensor18']
    actu = cont.actuators['act17']
    
    
    
    if sens.positive:
        cont.activate(actu)
        
    else:
        cont.deactivate(actu)
        

main()    

I realize the script is REALLY simple… I’m new to python. How can I make it so that the filter turns off when I release “R”?

Also, is there any way to make it remain on for about 5 seconds after I release “R”?

Filters continue to run after their actuator has been activated, so deactivating does nothing. In this case, you’ll want a 2D Filter actuator set to “Remove Filter”. As for keeping the filter running for a little while, use a timer of some sort (either the timer property built into game objects, or keeping track of time with Python’s time module).

By the way, it’s really a resource drain to apply a 2D filter every game frame (more than once, basically). So, trigger a filter only once when necessary, and deactivate it when unnecessary.