What I needed to know to use C# Signals in Godot
Recap: I was instantiating scenes and needing to connect signals in C#. In Godot. With minimal code understanding. The search for info is in this other post. (It's late in Aus and I'm tired so excuse formatting pls)
okay, so the way that I found worked was:
(21) get the node from the instantiated scene that has the signal.
(22) type that node, then the signal type, then connect it with += to a method. (the method is out of view, just trust me)
(If you're looking at the rest of the code above in confusion:
lines 6-7 are scenes I want to bring in. Can't bring them if I don't say their names like 3 times in the script istg.
lines 8-11 are filepaths that I'll be changing a lot, so want to only have to change them in one place.
lines 16-18 are how I added the start menu to my main scene.)
Here's the code a little highlighted for you, with some information about where I referenced it.
startmenu is the variable I made that is the copy if the scene tree you see below. The PackedScene, if you will.
Note: C# uses PascalCase for signals, so whatever Signal you want, remove any "_" and capitalise the 1st letter of each word. I did some examples in the image, also Pressed is used. There might be an extension of Godot that translates the Signal list for us, that would be great.
+= is how you connect a signal to a method. In this case, it means that whenever the NewGame button gets pressed, the NewGamePressed method will activate. (but you can call the method anything. it doesn't have to make sense)
var NewGameButton = startmenu.GetNode<Button>(NewGameButtonFilePath); NewGameButton.Pressed += NewGamePressed;
If you get into making custom signals, you will want to know more about -= which disconnects things, because they wont magically disconnect like normal signals do. Sounds gross and I don't want to get into that until I have to.
Anyway I hope this made sense to you (or future me when I inevitably forget how to code again.)