Hi, i'm trying to create a function that pauses the timer when pushing space and starts the timer again when using the same button. I'm using if and elif operators and i can't get the timer to start after pausing. Is there a NOT operator or equivalent?

if (Input.is_action_pressed("key_space")) and timer.is_active():
	timer.stop()
elif (Input.is_action_pressed("key_space")) and (timer.is_active() == false):
	timer.start()

@Teptai said: Is there a NOT operator or equivalent? Yes, there is. It's called "not" :)

if Input.is_action_pressed("key_space") and timer.is_active():
    timer.stop()
elif Input.is_action_pressed("key_space") and not timer.is_active():
    timer.start()

Yeah i tried that already so that means the problem is somewhere else. :) Well i learned something so thank you.

Well i got it to partially work but it would not start again with the same key so i still got something to figure out. Here's the code i'm using.

if (Input.is_action_pressed("key_space")) and timer.is_active():
	timer.stop()
elif (Input.is_action_pressed("key_enter")) and not (timer.is_active() == false):
	timer.start()

A negation of a negation is truth. Are you sure you want it to be not (timer.is_active() == false)? It should mean ""if it's true that timer.is_active". instead: elif (Input.is_action_pressed("key_enter")) and not (timer.is_active() == false):

you could use

elif (Input.is_action_pressed("key_enter")) and not timer.is_active(): or elif (Input.is_action_pressed("key_enter")) and !timer.is_active():

Yeah i wondered the same thing but for some reason the double negative approach just works. I tried your both examples and i couldn't get them to work. But right now my problem is that i can't use the same key, it has to be space & enter, space & space doesn't work.

Your problem is that is_active() isn't what you think it is. Try printing it every frame and you will see that it is never false. You want is_processing() instead.

Also note that (last I checked) Timer.stop() and Timer.start() don't pause and resume the timer. stop() sets the time left to zero, start() resets it to the wait time. Use set_active( bool active ) if you want to pause and resume. (in that case is_active() will work as you expect).

if (Input.is_action_pressed("key_space")) and timer.is_processing():
	OS.delay_msec(50)
	timer.set_active(false)
elif (Input.is_action_pressed("key_space")) and not timer.is_processing():
	OS.delay_msec(50)
	timer.set_active(true)

Ok here's the code that works, thank you all for the help. I couldn't find any mention about is_processing() command in the Godot Timer docs. I had to add a small delay or it will easily take the same push of the button multiple times. It's still possible to just keep the button down and repeatedly change the status but it works well enough.

You couldn't find is_processing() in the timer docs because it's a method of Node. Honestly I don't know why is_active() doesn't normally work, that's kind of a bug.

If you move this stuff over to _input() instead of _process() that will solve the multiple press issue. _input(event) only fires when something actually happens. And then you might not need the is_processing() check either. This should work:

func _ready():
	set_process_input(true)
 
func _input(event):
	if event.is_action_pressed("key_space"): 
		timer.set_active(false)
	elif event.is_action_released("key_space"):
		timer.set_active(true)

6 years later