How do I get Callables from built_in types?

Godot Version

4.2

Question

Hi all! I’m trying to connect a signal from a button inside of a child scene and have it emit a signal. However, when I try this, I get an error in the editor, I get this error -
image

I tried this with a string method and had a similar reaction.

I’ve gotten around this by making another function that just calls the emit function with the data it needs, but for future reference I was wondering how you can access the callables of a prebuilt class?

prebuilt class? you meant the button has a signal, example the pressed button, and you want to get the signal from parent?

No, more like…

If I have a string or a signal and I try to call a method on it, I can simply do something like:

"hello".to_upper()
my_signal.emit()

However, if I wanted to get the method/callable, instead of calling the method, it throws an error in the editor.

var make_hello = "hello".to_upper
var emit_signal = my_signal.emit

I get “Parser Error: Cannot find member “to_upper” in base “String”.”

However, if I do this with script that I made myself, I don’t get this error.

Does that clear up my question?

i think you will need to look at example in Callable — Godot Engine (stable) documentation in English

Callables only work for Objects. Signal, String, Array, Dictionary, Callable,… aren’t Objects but Variants

You’ll need to use an anonymous function (lambda function) like:

var signal_emit_callable = func(level): level_selected.emit(level)
1 Like

Ah yes, this makes sense, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.