Parent Node or Child Node and get_node(), .start()


I'm confused should i really need to use or put another Nodes inside Parent Nodes #ParentNode>ChildNode

to be able to use the Signal.

get_node() - this one is required to use to emit, trigger or call the Signal?

.start() - this code are include or always need to write if we use the get_node()

  • a
    andrewjhaugen replied

    Hi Richard!

    In answer to your first question: do we need to have a child node in order to use the signal? The answer is no, we don't necessarily need that. Many nodes from all over your Game can respond to a variety of signals, however. each situation requires special care when connecting signals to the responders. It just so happens that connecting a child's signal to a parent's method is one of the most straightforward ways to do this, so we present it this way first.

    Second question: is get_node() used to emit, trigger or call the Signal. Let me try to break it down best I can.
    The Timer node has a method called "start()". This method when called will set a timer in motion.

    The Timer also has a built in signal called 'timeout' this signal is automatically emitted from the Timer once time reaches 0:00. This is built in functionality that the Timer node has, we don't need to necessarily understand how its implemented under the hood. For our purposes all we need to know is that if we ever call start() on a Timer node, it will countdown and then when done it will emit a signal called "timeout".

    So why do we need get_node("Timer")? The reason is that this script is attached to the parent node, which is Sprite. If we tried to call "start()" without getting the Timer node we would get an error. This is because the Sprite node does not have a method named "start()" We are in the Sprite node, yet we want to call a method from a different node. How do we do this? That is why you need "get_node("Timer")"

    1 love
  • RichardO replied

    So when should i need to use it?

  • Nathan Lovato replied

    The general answer is, "it depends." It depends on each scene's needs, depends on the nodes at hand, depends on how you decide to structure your game. I invite you to keep going with the course, it's something you'll naturally learn through practice.

    1 love