+5 votes

I came from Construct and guessing that connections kind of similar to event system in Construct.Any info regarding to this topic is much appreciated since Godot is my first scripting game engine.

in Engine by (20 points)

@alextro ~ If any of those answers was the correct one, would you mind checking its "Selected" checkbox?

Ah okay.. not familiar with QA system before.

4 Answers

+16 votes
Best answer

Yes, Godot's event system is based on signals.

The Godot documentation has this brief introduction to them from GDScript: http://docs.godotengine.org/en/latest/reference/gdscript.html#signals

Here is some extra information:

The connect method has another optional parameter to specify the connection flags (you can use multiple flags with the | operator):

emitter.connect("signal", node, "method", [], CONNECTION_DEFERRED | CONNECTION_ONESHOT)
  • Deferred connections (CONNECTION_DEFERRED) queue their signal emissions and the connected methods are not called until idle time.
  • Oneshot connections (CONNECTION_ONESHOT) automatically disconnect themselves after the first emition.

You can also connect signals in the editor by selecting a node and clicking the plug button in the Scene dock:

img1

This will popup a dialog with the list of signals. Signals declared in scripts are also visible. You can select one and click Connect.., which will popup this dialog:

img2

In this dialog you can select a target node and method (optionally marking Make Function to create the method). You can also bind extra parameters if the target method requires them, and mark connection flags.


This basic example increases the button text by 1 when you press it:

extends Node

var counter = 0
onready var button = get_node("MyButton")

func _ready():
    button.set_text( str( counter ) )
    button.connect("pressed", self, "_my_button_pressed")

func _my_button_pressed():
    counter += 1
    button.set_text( str( counter ) )
by (488 points)
selected by
Hi neikeq.
So if I'm not mistaken, connections is signaling an action to target node when condition is met or it just only set the flag?
Signals are emitted when certain action happens. For example, the `BaseButton` class emits the signal `pressed` when the button is clicked. This will call all the methods that are connected to that signal.
I updated the answer with an example increasing a counter everytime a button is pressed.
Ah I'm starting to understand.
Is it necessary to pass a variable as a string when set a text?
Yes, that's why I use str(). Otherwise you would get an error like this:
`Cannot convert argument 1 from int to String.`
+1 vote

Hi alextro. I think you will find everything you need to start here.
http://docs.godotengine.org/en/latest/index.html

Also, if you have a questions or a problem that needs to be resolved fast, drop by at irc.freenode.net #godotengine - for example from http://webchat.freenode.net/?channels=#godotengine

by (721 points)
Thank you Freeman for offering an assistance. Hopefully in next chance I must discussing in group chat.
+2 votes

They're also covered a bit in this video: https://www.youtube.com/watch?v=4g-yktcH0jw&list=PLBgwKMnonTew0Z0xRA8rJch1aB3-Qnm1T&index=2 The other videos in the series have some pretty useful stuff too.

by (549 points)
I watched the node series and the videos help me understand the idea.
0 votes

There's an in-depth guide about Godot's signals published on gamedev.live. It starts by explaining the basics. Then it dives into the advanced features (passing parameters, bind array, flags, etc)
https://gamedev.live/gdscript-godot-signals-in-depth-guide/

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.