The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

Hi friends, I am trying since yesterday making some code work that is dependent on a custom signal.I am having some problems making it work, maybe it is the way my setup works.

This is the signal:

add_user_signal("go_to_next_text",[{"name": "current_chapter", "type": TYPE_STRING},{"name": "current_dialog", "type": TYPE_STRING}, {"name": "current_text_finalized", "type": TYPE_INT},{"name": "total_texts", "type": TYPE_INT}])

Then, on the needed part, I connect it, together with the needed arguments that are:

connect("go_to_next_text", self,"go_to_next_text", [chapter, dialog, start_at, dialog_array.size()])

The mentioned function go_to_next_text:

func go_to_next_text(chapter, dialog, start_at, total_text):
    print("FUNC STARTED!", chapter, dialog, start_at, total_text) # testing purpose
    var accept = Input.is_action_pressed("ui_accept")
    while not accept:
        if accept:
            emit_signal("go_to_next_text",chapter, dialog, start_at, total_text)

but it looks like the function is never called as I don't get even the print "FUNC STARTED"

I have already read the documentation about signals and even the reddit posts relevant to the theme... but I wasn't able to figure it out what I am doing wrong

Also, I know this is another kind of doubt, I can create another question, but since I am on the theme, is it possible to simplify this process by making a yield(object, "go_to_next_text", array_with_arguments) and pass the arguments directly on the yield somehow?

in Engine by (234 points)
edited by

Can you make a sample project for it?

I dont know add_user_signal method, but if i do simple

extends Node
signal go_to_next_text(chapter, dialog, start_at, total_text)

func _goto(chapter, dialog, start_at, total_text):

func _ready():
    self.connect("go_to_next_text", self, "_goto")

    emit_signal("go_to_next_text", null, null, null, null)

it works as expected (print out "gotcha!" :) )


var accept = Input.is_action_pressed("ui_accept")
while not accept:
        if accept:
            emit_signal("go_to_next_text",chapter, dialog, start_at, total_text)

really? :)

# let accept be false, so:
while !false # = true, ok, go to cycle
    if false # do nothing
        emit # never called
    # stay forever in loop (accept never change)
_activate_doomsday_device() # dont worry :)


# let accept be true, so:
while !true # = false, do nothing
    if false # never called
        emit # never called
    _activate_doomsday_device() # dont worry :)

edit: minor formatting issues
edit2: added silly joke with doomsday device :))

Hey friend, thanks for replying.

I got the help of one of the devs and looked like I was trying to get blood from a rock

The signal is kinda like a shortcut to add_user_signal, other than that, they work the same.

I solved my problem by making global variables that could be changed based on the results of other functions...
Not the most elegant sollution, but it is now working flawlessly.

It was the last thing I was trying to correct/tweak before releasing my plugin to the public


Looks sweet, i will give it a try (would be very cool to have texts in xml & external editor for translators), but right now, i cant make it work (pretty sure its PEBKAC).

Btw & OT, "smrt" means "dead" (as in "black dead") in my language :D

Another friend from the community pointed me that, which was not the intention at all.
It came from the Simpsons, when the original voice actor for homer, mispelled SMART when talking how smart homer is... The situation was so funny they left it there.

The video

Why the name? Well... I always felt SMRT(an idiot, not death haha) while making this plugin, as I was creating while learning. Since it is not offensive, I kept the name.

1 Answer

+6 votes

This is an example for signals with multiple arguments:

signal coin_taken

func _ready():

func take_coin():
    emit_signal("coin_taken", 100, "gold")

func _ready():
    var coins = get_tree().get_nodes_in_group("coins")
    for coin in coins:
        coin.connect("coin_taken", self, "add_coins")

func add_coins(number,label)
    print("You have got " + String(points) + " " + label)

In general:

Script1: emit_signal("signal_name", arg1, arg2, arg3)
Script2: coin.connect("signal_name", self, "triggered_method")

by (332 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.