0 votes

I am trying to connect a signal to a method and I have successfully been able to connect the signal to the function, but when I try to print the parameter value it says it's basically the zero value of whatever data type I tried.
Here's what I tried:

startButton.Connect("pressed", startButton, nameof(this.startMenuPressed), new Godot.Collections.Array(){"start"});

and the function is as follows:

public void startMenuPressed(String buttonName){
        GD.Print($"name: {buttonName} name equal: {buttonName == "start"}");

I also tested buttonName == "" and it printed out to be true. How can I pass the string value to the function? I also tried instead of the "start" directly, having a String variable that was equal to "start" instead, same results.

Godot version v3.3.4
in Engine by (52 points)

1 Answer

0 votes

I figured out the problem was that the target object was wrong, instead of

startButton.Connect("pressed", startButton, nameof(this.startMenuPressed), new Godot.Collections.Array(){"start"});

it should be

startButton.Connect("pressed", this, nameof(this.startMenuPressed), new Godot.Collections.Array(){"start"});

Then it works as intended.

by (52 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 webmaster@godotengine.org with your username.