An extremely mild cough will not stop me from completing the current objectives before the month ends damn it.
Last time we left we needed to make the arrows Do Something, so let’s get to it.
If you’ll remember, last time we left some button triggers on one of the scripts, let’s do something with those.

Simplest operation ever: if it’s bigger than 0 allow it to subtract and if it’s smaller than the max amount of pages allow it to add. Including also a print statement just to check the numbers move around as intended.
We test aaaaaaaaaaaaaaaaaaaaaaaaaaaaaand nothing, not even an error.
It’s at this point that I’m realizing that I never added a click mask to these buttons.
One blank square later it still doesn’t work and I’m realizing that that’s because I made the signals when the buttons were still part of that scene but then they became prefabs which I’m assuming cuts the premade “double click to connect” signal method so time to actually learn how to make and connect those manually!!!!
Now, the main obstacle that I’m running into is that the Godot Tutorial mainly explains this in terms of connecting to things that are inside the same tree. The principle of it all is that you have a signal emitter and a signal receiver, but my point of reference doesn’t apply to what I’m doing right now despite the fact that it seems like I can.
This is one of those cases where I fundamentally understand what’s going on and what should be done in theory but because my brain hasn’t adapted fully to the idea I’m essentially making noises like a faulty HDD.
Let me retrace out loud bit by bit what I understand about this matter.
So on paper, a signal is… exactly that, a thing that you create as a unique indicator that you then tie to an event happening elsewhere, so that literally when the signal is emitted and they receive it something happens.
In the context of what we’re doing here, we need a function to trigger… so the first thing we’re gonna do before anything else is change the functions we were using.

Just the name, though.
Next, we need to connect signals to these functions, the idea is that when the signals are received they immediately trigger these functions. This was one of the first things that had me stumped because I thought there needed to be some specific term defined, but thankfully the connections can come from strings.

As seen here, where I’m connecting both earlier functions to a hypothetical leftpage and rightpage elsewhere in the tree. If I understand right, this SHOULD allow me to trigger the functions with those signals with no concern for if the signal emitter is currently in the tree, which is something that makes sense since it’s the sort of function that would allow you to do things like… bombs in a bullet hell for example.
So in theory we next need the arrow buttons to emit these signals.
First I wanna calm some paranoia by making sure the buttons actually work so we attach a script and add a simple print statement.

We test…

We good.

Next let’s replace it with signal emission and see what happens.

I think I know what this is, I THINK it’s just because I skipped declaring the signal name.

So we try this.

Okay, it’s not as freeform as I thought. The signal does need to exist within specific contexts.

In this case if we move the signals declared to this script one of the errors stops.

But trying to press the buttons throws the error that the signal I’m trying to use doesn’t exist.
Now, here I immediately run into one of proverbial the bottlenecks because I need to connect to an object outside of this tree, so old problem but at least some progress was made in understanding the whole Signals deal so let’s use it.
The current stoppage is that we need to connect signals through objects we don’t have regular access to outside of runtime…
…this problem or what’s essentially the same problem is something we actually faced earlier, that’s when I discovered global variables.
If the only issue right now is the access one, can’t I just declare all those signals in a global object like the variables?
I mean in theory nothing’s stopping me from using the same Global object, but let’s keep things clean.

Huh, didn’t notice that you can add scripts alone as Globals. That’s good to know.
Right so we declare the signals in a global space

Then we connect said signal to a function, because it is custom it needs to be emitted, but when it is emitted it will make the indicated function kick in.

Then we make the buttons emit the signal.

Am I right? Will this work?

It needs to be a string…

But using a string tells me it doesn’t exist because it has no access to the global bit.

Okay, so apparently emit can be used standalone like this.
Will it work though?

I’ll be damned, it did.
So allow me to think out loud the way I’ve come to understand this.
“Signal” true to its name could be defined as a “frequency” on something like a walkie talkie. Define a name and you have a frequency through which you can send stuff.
The signal can be defined in one place but used in an entirely different place, again, it’s just a frequency like a radio.
I feel like the two things that confused me the most were the fact that you usually need things like variables locally so the fact that you can define a name on a parent and have the child use that name as part of the intended mixed me up… that and the fact that it keeps jumping between namespace items and strings so much.
Not saying it’s bad, I can see not only the intent but also the ways it could be used but man it was hard to wrap my head around for whatever reason.
Any other day we would’ve stopped here, but I want to get a bit more done so I can hit that very arbitrary goal I have.

So in theory (incomplete theory mind you), the intent is that we reuse the command that creates the buttons to begin with with a bunch of stuff that the carrier object has saved such as which menu to regenerate and on what page.
Also here’s a fun fact: get_node(get_path()) is technically equivalent to using self, but using self here points the reference to the SCRIPT and not the node, which is interesting.
One problem this IMMEDIATELY faces is that with the code as-is, we’re gonna have a growing nested tree every time we switch pages, so we gotta add an extra condition.

On paper the idea is that if buttoncarrier already exists then it just points the variable to it instead of creating it and doing other stuff.

Another thing we’re doing is making a holdref variable that will save the reference for the bit that saves all the buttons, so we can delete it faster.

Let’s quickly see if that shows up on the remote resources tree.

A crash, but that’s from the is_instance_valid bit, I think.
Let’s do something simpler.

Extra paramenter, True means the carrier already exists, False means the carrier must be created.

So in this command it’s True

While here it’s false.

When false it does all the creation bit, but if it’s true it just kinda points at itself.
Right, we just wanted to see the remote tree but things crashed, let’s try again.

………the navigation bar is gone.
They’re still there in the tree too…
After panicking I realized that I changed buttoncarrier to a Node2d and that was the cause.
I checked the resource tree and the reference to the bag of buttons (my mind is sizzling a little, cut me some slack) works as intended but there’s one more issue….

If you open and close the Move menu, then the buttoncarrier item gets duplicated, meaning the whole thing is probably not being cleared out of memory properly so it adds one more instance.
Moving the command from on_enter_tree to ready fixed it though, but I’ll definitely have to keep an eye for potential weird behavior (either from ready somehow not being ideal to just the change as a whole on principle).
Back on track. With the reference internally in the container to the buttons bag, the way to go IN THEORY would be “button press deletes button bag before regenerating the buttons.”

Will this work?

It did not.
So the problem seems to be the get_node get_path bit.

Problem is that using self, as mentioned before, throws an error.
After my soul left my body for five seconds because I’m getting really sleepy, enlightenment was achieved and clarity came to me.
Every Node2D has plain Node, just make the command take Node as a parameter instead of Node2D dumbass.
The red highlighting seen above actually stopped, but will it work?

Partial success.
Partial because the navigation bar was being duplicated also.

We do this and it mostly fixes it but now the numbers don’t change.
It’s fine, I’ll fix it tomorrow, I’m getting real sleepy right now.
We’ll add a signal that triggers the numbers changing, I’ll check why the page doesn’t reset when reopening and we’ll add the actual button functions.
It’ll all be fine.
