Search code examples
timergodot

The time_left in timer is always set to 0


I made an if statement that does a thing whenever the time_left on timer equal zero but the problem is that time_left is set to zero from the moment the scene is loaded.

Here is the function

func _process(delta):
    if $turn_timer.time_left == 0:
        if e_next_move == 1:
            e_is_attacking = true
        else:
            turn_end()

        if e_health > 0:
            e_nextmove()
        else:
            e_next_move = 0
            $enemy.hide()
        $turn_timer.stop()

I set the timer to being "one_shot", also "wait_time" was set to 3. Also I found a way to fix this by entering "$turn_timer.start(999)" at the end of the code but this sounds like a bad way to fix this. How can I fix this problem?


Solution

  • Tried and yes the timer is set to 0 not matter what. I assume that is because Timer is automatically set to false when entering a scene, so it won't start basically.

    You have to check the box "Autostart" in the inspector or you can set your timer in the _ready() function :

    func _ready():
       $turn_timer.wait_time = 3
       $turn_timer.start() 
    
    func _process(delta):
       print(int($turn_timer.time_left)) # 2... 1... 0...