Does "!" work in this situation?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Chevi

I’m trying to check if an action is not pressed and I think this should work but I’m not sure.

if !Input.is_action_pressed("Move_Left") or !Input.is_action_pressed("Move_Left") or timer_counting == false:

all I’m trying to do is basically an “else” to the input detections but with the added check for a timer that serves as a cooldown.

You don’t have to put in the extra !Input.is_action_pressed("Move_Left").

Your code will check for whether one of those two statements is true. The implication of the code if !Input.is_action_pressed("Move_Left") or timer_counting == false:, though, is that it will return true for any situation where Input.is_action_pressed("Move_Left") is not being pressed , or the timer isn’t counting. It may be better to first check for the cooldown and then check for the input, e.g.

if not timer_counting:
     if Input.is_action_pressed("Move_Left"): # Or "Move_Right", "Move_Up", "Move_Down", etc.
            # Your glorious movement code goes here.

Hope that helps.

Ertain | 2020-07-11 16:17

personally I like not instead of ! because sometimes when trying to find an annoying bug and you know your error was because of ’ ! ', which can be hard to find sometimes.

shmellyorc | 2020-07-11 23:11

Wow, Thx so much

Chevi | 2020-07-14 20:47

:bust_in_silhouette: Reply From: dustin

it should work, but the best way to check is to compile and test it!