C#"pressed" Signal for array of buttons not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AlMoeSharpton86

I am going through the buttons using a for each loop, and they should attach a signal on build.

I have some buttons that should be clickable on build, but it doesn’t seem to be working. I get no errors, the buttons don’t respond at all.

Anything I’m missing? Maybe it’s how I write the array? (The “MenuButton” is just how I get access to the “scene_to_load” String variable, it should be of the Button type.

  foreach (MenuButton button in GetNode("Menu/CenterRow/Buttons").GetChildren())
     {
      
    button.Connect("pressed", this, nameof(OnButtonPressed), new Godot.Collections.Array() { button.scene_to_load });

Where I’m getting the “MenuButton” from to access the scene_to_load variable.

public class MenuButton : Button
{
    [Export]
    public String scene_to_load;
    
   


}

Then it should excute this method (The scene_to_load variable should load & open the corresponding scene the buttons are linked to, but don’t seem to respond.)

 void OnButtonPressed(String scene_to_load)
  {
    GetTree().ChangeScene(scene_to_load);
    //scene_path_to_load = scene_to_load;
  }   

Thank you very much for your help! Addtional info, can be provided if needed, thanks.

:bust_in_silhouette: Reply From: AlMoeSharpton86

Was just incorrect C#

I was writing the line

  button.Connect("pressed", this, nameof(OnButtonPressed), new Godot.Collections.Array() { button.scene_to_load });

It should be more done like (May have to change how it gets the “NodePath”
on the “GetNode” bit & array)

 GetNode("Menu/CenterRow/Buttons").Connect("pressed", this, nameof(OnButtonPressed), new Godot.Collections.Array() { button.scene_to_load });

I was writing it similarly on how you would do it in GDScript, just had to read the Signals documentation again! My mistake :slight_smile: - https://docs.godotengine.org/en/3.1/getting_started/step_by_step/signals.html#connecting-signals-in-code