 Singles in Godot are one of the most powerful and important concepts to learn and understand. In this video, we will make use of some signals, we'll add our own custom signals, and we'll wire them up, and I'll explain them the best I can. I've got an empty project, nothing fancy, we're in Godot 4.0, let's add this SVG icon to the screen. Let's go ahead and we'll add a timer node. This timer node will auto-start it, and we won't one-shot it, and we'll have it be one second. We'll go ahead and save this. What we're going to do, we'll add a simple script to main.gd that says, in every frame, we'll take our icon and we'll rotate it. If you've watched my other videos, I love rotating this icon. It's my favorite thing in the world. We'll set a variable that says rotate icon, and we'll set it to true. We'll say, if rotate icon, rotate the icon. Run this, and we haven't wired up or used signals yet, but we've got our rotating icon. Now, our timer, back to that. In the inspector, we've got wait time one seconds. You can change this as needed. We'll keep it at one second. Now, signals, let's get into it. You click into node, and then there's two sub tabs here, groups and signals. This video is about signals, not groups, so we'll talk about signals. Each node, based on the type it is, has different signals. So timer has timeout. You can hover over it, and it says, omitted when the timer reaches zero. Cool. Okay, that's really useful. Signals are events that happen that we can wire up and react to accordingly. Let's click our sprite to the icon. Oh, frame change, texture changed. We're not really worried about those, and there's some others that exist too, like on all nodes, but just want to show you that they vary. Now, what you do is you can here, you can go down, click connect. I like double click. It's kind of nice, and it says from signal, timeout, connect to script, and you can filter nodes. We're going to connect it to our main node, which already has a script. So instead of clicking something else, we just leave it clicked on main, and then you have receiver method. This is quite nice. This is a new function that will be added or be used if it already exists. You can use the picker too to pick, but we're not going to pick it. We're going to create it. You just click connect. That goes ahead and opens up the script editor with that function created on timer timeout. And it's called every time the timer times out. Let's just do print debug timer timeout, and go ahead and save that. If we go back here, we might have to rerun our game to get that wired up. And our timer down here, you see it's every second timer timed out. Great. So we know that this signal is wired up, and you can see here this green icon in the left gutter. You can click that, and you can see which signals are connected to the method. Timers timeout is connected to the main script. Excellent. Now instead of print debug, what we're going to do is we're going to have it change rotate icon to just be to negate itself. Now we go ahead and save that. Oh, our timer, our rotating stops every second, and then it resumes. And we can go into timer. We can go into the inspector, and we can change it to be every three seconds. So it gets a little further along before it pauses. That's pretty nice, right? That's the basics of a signal. When you have a scene or an object or a node that does something, and you have another node or scene that needs to react based upon that, it could even be itself needs to react upon it. You use signals to communicate and say, great, this happened. All right. So that is using a signal from an existing node. What if you want to code up your own signal? Well, let's go ahead, and we'll go into icon, and we'll attach what's actually clear out our timer, because how to do this, how to best do this. Let's take this. Let me back this up so I can give you that source when it's needed. But we're going to go ahead, and we're going to add, we're going to kind of get rid of our timer and redo some things. So we'll delete that. We'll even delete this, because that doesn't do anything to understand. We'll just pass through right now, delete the timer, yada, yada, yada. Okay. Let's go back to our 2D view for a second. Now, what I want to do is make a UI label. So type in label, add that node, and we'll just rename this label. We'll call it rotating status, and we'll say rotating. And this label is going to be our UI for monitoring whether or not this icon is rotating. We're going to change the text and react based upon our custom signal. Okay. So maybe we should have kept the timer and all that stuff, but we'll do it our own way. So right now, if we run this, our icon doesn't rotate, and this label is a lie. Let's go ahead and we'll add a script to our icon, and we'll send our signal from our icon. So I'm going to name this just icon. It's sprite 2D. We'll quickly recode our thing and say rotating true, and we'll say process. We'll say if rotating, right? Instead of saying icon that rotating, we'll just call rotate method on ourselves because we're in the side of that. Okay, run this again. Now our icon should spin again. That's, there's no more lies. Now what we want to do is wire up a signal ourselves that says, let's make this so we can toggle our rotating, and then we'll go ahead and add our signal. I'm going to add an input event callback, and we'll just say event is action pressed, and we'll use UI accept because that's a basic one that exists. And if that is just pressed, which I think should be the space bar, we'll say rotating is false. We'll say rotating is the opposite of rotating so it can toggle. Great, run that again. Space bar toggles it. Now what we want to do is take a signal and emit it every time that happens so that our UI can update accordingly. So we're going to take our input, and every time that rotating changes, we'll send a signal. So we'll say signal, say rotating changed. We'll say rotating toggled, and then you can, in your parens, you can say, you know, what this, you can give it like a name to represent what it is, and a type signature. So we'll say rotating, maybe we'll make it is rotating, and this is unrelated to this. That's why I renamed it because I didn't want it to be confusing. And that's a boolean value. Now, if the action is pressed, or we have this signal, right, let's slow our roll a little bit, and let me make this smaller. So we have this signal. If we go to icon, and we go to node, you can see here in icon.gd, we've defined this single signal, rotating toggled. And we can even wire it up, wire it up. So we can say on icon, rotating toggled. And if you click connect here into main, we have a new method, just like we did with timer. But instead, we made this ourselves. And you can even see here, we have is rotating, which is the boolean. What we're going to say here is, if is rotating, we're going to set rotating status dot text is equal to rotating active. Else, rotating status dot text is equal to rotating paused. That is the gist of the code. Now, if we run this, and toggle it, our text here and our label didn't update. Very interesting. Why is that? Well, we have to emit our signal, which says, in our code somewhere, we need to go ahead and say, tell the world, tell anyone who's listening, that this event occurred. So all you do is you say rotating toggled, the name of the signal that we defined up above dot emit. Now, normally, you would just do dot emit with nothing if there was no signal value to send. But for us, we're going to send rotating as our parameter. So anyone listening can get this is rotating boolean. So now that we did that, we can run our game. Oh, now it's changing. And you could see that the a is not capitalized because it changed from our placeholder text. So you could go ahead and make that better. But now, to summarize what we've just done is we've taken code happening an icon, or we've taken an event, a signal happening an icon, and we've let elsewhere in our game know that when this event happens, react accordingly and change your state, change the text, change whatever. And this could have been in rotating status. We could attach the script there. But we had main. It's easy enough to have in these simple demos have the parent, the root of the scene manage its children stuff. But if you had a complicated game, you might want the rotating status text to be responsible for this. So it's up to you. And let's make this code a little bit better, right? We'll say var text is equal to an empty string. And we'll just assign it accordingly. And then here we'll say that code's just just a little bit better, I guess, debatable if it's better. But I like it more. So now we toggle it. And you could even make it so that on ready, we admit the signal ourselves. And we say, based on this default value, this this like makes our code more true, it gets rid of that placeholder active with the capital A, and uses our code to actually let the parent node know when it's ready, what its state is. I hope that helps you see how signals work, because you've got timers, or you've got existing nodes like our timer, where you can find and see signals that you can wire up and connect to, right? And you do that in the node tab. Or, and this is pretty common, you're going to want to create your own signals if it doesn't exist for different game logic events that happen. And all you do is you type signal, you do the name of the signal, and then the data that you want to send. And this bull is optional. I like putting it though, because then you know, like, okay, that's sending a bullion. That's helpful. And then you take that signal in that script, and you just admit it. And your game can react accordingly. I hope that helps. You better understand signals. They're really cool. They're really helpful and useful. They're a foundational part to building games with Gino. Thank you so much. Catch you later. Bye.