Hey all, not sure what I am doing wrong on this one. Tried looking at the docs and it looks like I am doing everything right, so I am at a bit off a loss. Not trying to do anything crazy, just have a timer node start.

`extends Node
@onready var timer = $Timer

func on_death():
timer.start()`

The Timer node is a child of this node, I can even check with print() and I do have a correct reference to the Timer node. This function is being called, I checked with print(). But the timer never fires and I don't know why.

func _on_timer_timeout():
print("Timer done")

I've got this code later for when the Timer hits 0, but this code never gets called. I linked it through the Nodes section of the Timer node, so I am not sure why this isn't working. Any ideas? Does start() not start the Timer?

As a side note, how do I restart a timer? I want it to hit 0 and fire the code, then reset back to the max but not keep counting down. Count down to 0 once, fire the code, then reset and wait to be started again. Is there a "reset()" function or does it automatically reset after hitting 0?

    Does on_death() do anything else, such as call queue_free()?

    CorvaNocta how do I restart a timer?

    If its one_shot property is false, the Timer will restart automatically when it times out. If one_shot is true, you can restart it by calling its start() method.

      DaveTheCoder It does, but nothing that should be interfering with the code:

      func on_death():
      if container:
      for p in players:
      p.inventory.add_item(container.item_in_container)
      players.clear()
      get_parent().deplete_node()
      get_parent().is_alive = false
      timer.start()

      And that is good info about the one_shot, I have it set to true so it sounds like it works the way I think it does

      • Toxe replied to this.

        CorvaNocta What are the settings of that timer? Wait time, autostart etc.? And, silly question I know, but are you sure that the timeout signal is connected to your callback function?

        What is the indentation of the code in your on_death() function? Could you either reformat the code here or post a screenshot? The indentation level of timer.start() is not clear.

          Toxe

          Sorry I couldn't get this over the weekend. But here's the setup so far. Not sure why it isn't working, it looks like everything is properly working to me.

          • xyz replied to this.

            CorvaNocta We don't see any actual signal connections in your screenshots. Also, who calls on_death()? Put a print statement or a breakpoint in that function to check if it gets called.

              xyz Is the "Timer (Connecting From)" not a signal connection? Or does that need to be coded differently?

              Maybe I can describe my process to see if I am missing anything: If I click on the Timer node, and switch to the Node tab, I double click on "Timeout()" which opens a window of the current scene tree (The Tree_Node scene tree that you see on the left) and I can select the Health node. When I do it generates the "func on_timer_timout()" function on the Health script. That is all I have done so far, is there more that has to be done? The console shows me "Connect 'timeout' to 'on_timer_timeout" after doing this, so I am assuming they are now connected.

              The take_damage() function calls the on_death(). It does fire properly, everything in the on_death() func works, just not the code for starting the timer.

              • xyz replied to this.

                xyz Huh, so when I redid the steps that I mentioned, it didn't create a new func for the on_timer_timeout(), but it did go to that part of the script. And I noticed the green reference under the timeout in the node section. So now it is working.

                I don't know how it happened, but I guess somehow the reference got lost even though the code got generated. I don't know how it would unlink. Maybe I deleted the Timer node and created a new one and just don't remember doing that? That would leave the code behind but erase the link. Who knows. But it is working! So thanks for the help!

                • xyz replied to this.

                  CorvaNocta They are connected if you see green callbacks listed under signals in the Node tab. There aren't any in your screenshot, although the connecting process you described is correct.

                  CorvaNocta Yeah always check those green things in the inspector. Those are the actual existing connections. Having a mere _on_something() function doesn't mean that the signal is connected to it.