I'm having difficulty to discover how to convert a code from godot 3 that would be a connection passing the name of the connected button like this:

button.connect("pressed", self, "initiate_build_mode", [button.get_name()])

This is the code that should work in previous versions but now it seems to be like this:

button.connect("pressed", initiate_build_mode)

And it was all fine until I had to use it passing an argument like the name, so when I try this:

button.connect("pressed", initiate_build_mode(i.name))

Godot says it isn't a Callable, but a Nil in argument 2, and connect should only have those 2 arguments. It only works when it passes just the function name like the second example. So how to proceed?

And also it prints the argument passed, the string name, and runs the rest of the code as if it worked but it shows error and close the running scene.

    Canichim Optional binds are now supposed to be bound to the callable instead of passing them as arguments to connect()

    button.connect("pressed", initiate_build_mode.bind( button.get_name() ) )

      Canichim

      button.connect("pressed", initiate_build_mode)

      initiate_build_mode in this call is a Callable. A name of a function, if you will.

      button.connect("pressed", initiate_build_mode(i.name))

      In this line you actually call initiate_build_mode() with the argument i.name and pass the result of that function call (null) to connect().

      Try this:

      button.pressed.connect(initiate_build_mode, [i.name])

      Or should the last argument be [button.get_name()], like in your first line from Godot 3?

      https://docs.godotengine.org/en/4.1/tutorials/scripting/gdscript/gdscript_basics.html#signals

        Toxe Thanks for the explanation, but I understood what would be a callable in that context, what I called "name of the function" hehe. The problem was not finding the new version of doing it in the docs.

        This code would not work because the new connect function do not accept it, it only can receive the Callable and a flag.

          Canichim In 3.x all functions needed to be referred to by strings containing their names. In 4.x they added Callable type. It is basically a reference to function, making functions so called first class citizens as is the case in most modern languages.

          So now you can assign function references to variables and pass them as arguments. The latter is precisely what is happening here. You're passing a Callable (function reference) as an argument to connect().

          This is much more efficient and flexible than using strings, and also produces simpler code. It's a quite powerful feature greatly improving GDScript as a language.

          Canichim This code would not work because the new connect function do not accept it, it only can receive the Callable and a flag.

          Oh you are right, my apologies. But aren't the docs wrong in this case then?

            Yeah, and it turns out we can use two forms, passing the signal name as argument, or calling connect from the signal property, as if accessing it like a property, with a dot.

            if we call connect directly from the node, it requires 3 arguments, one being the signal: StringName.

            If not, it requires 2 arguments, one being the callable and the last one being the optional flag on both ways.

            Toxe It is right, if you read the connect method doc, it defines the method as this:

            int connect ( Callable callable, int flags=0 )

            and uses your way of doing it with:

            button.pressed.connect(_on_pressed.bind(button))

            @"DaveTheCoder"#p121582 Ah yes, that looks about right indeed!