Hey everyone, in this video tutorial we are going to be talking about what flow control nodes are within blueprints scripting. So what you see in front of you right now I am within my Level Blueprint, I simply came under blueprint Level Blueprint are a bunch of flow control nodes that you can utilize when scripting your game. Now what are flow control nodes? Well, flow control nodes allow you to choose what script or what functionality executes based on whatever conditions you put in place. So some examples that I can think of is you can decide if a door in a game is locked or unlocked. based on whether or not you have a key.
Does the player have the key true or false, right? You can make it so that you can interact or open a chest once to get the goodies out of it and then never again that's another example. So in the two examples, decided whether or not you can open up a door based on whether or not you have a key, you would use a flow control node called a branch node. In the example that I gave of interacting or opening a treasure chest just wants to get the goodies out of it. But then never again, you would use a flow control nodes such as do once you can open it up once and never again. So all these are examples of flow control nodes.
And how did I get these? Well, within your right click menu right here, if you just do a search for flow control, you're going to see a whole selection of different flow control nodes. There's a bunch of them here, these do n do ones flip flop, we're gonna examine some of these. There's some more programmer ones like for loops, and while loops we're not going to get into and then there's a whole series of switch on various names right here. We're going to explore just one today called switch on So let's demonstrate because seeing is believing, let's demonstrate a few of these nodes at work. The first one we're going to try here is the branch node.
And to help me get started here, I'm just going to bring in an event. So I'm going to right click, type in H will bring in an H key press event. And next thing I'm going to do is I am going to hold down the B key, B as in boy, and I'm going to left click to bring in a branch note that one's got a shortcut to it because it is very commonly used. Okay, next, I'm just going to right click and do a search for a print string node. And I'm actually going to hit Ctrl C with that highlighted and Ctrl V to paste Ctrl C Ctrl V, because I want two copies of this. And I'm going to drag and drop a wire from my true pin here to my Print string up here, then out of the false pin.
I'm going to plug this into my print string down here. And what I'm going to do is in this top most print string, I'm going to type in the word true. And in the bottom area, I'm going to type in the word false. So now when I press the H key, this branch node is going to evaluate whatever condition I have here. checkmark means true, and it'll fire out of this true branch right here. If I uncheck this, that would mean the condition is false.
And it would fire out of this pin and print false to the screen. Now note, I could plug in a variable here, I could create a variable called Heck, we could call it has the key question mark. And then we could compile because it's telling us to compile And I could click on this little checkbox right here to say yes, he does have the key. So I could even plug in a boolean variable right here saying yes, I do have the key to then show that yes, I have the, the key. Let's see this in practice. If I press the H key right now, I do have the key because I checked Mark Yes, over in the Details panel for this variable.
So I should see the word true. Okay, so pressing the H key right now look in the upper left hand corner of the screen, you can see it says true. Now if I change the value of this variable to false, now I'm saying I do not have the key that is false, so I should see the word false when I press the H key. Okay, now let's do a quick sampling of showing off what to do once no does I'm just going to delete out this has key variable to delete out my branch, we will delete out one print string. And I will drag in my do once note here. And let's hook up a sequence like this.
And when I press the H key, we're going to one time, print out this string. So I'm going to change the text here to say, done. Alright, so this should execute, only the first time I press the H key. If I press it again, it should not print the word done. So here we go, hit play. The first time I hit the H key, you see the word done.
Now on subsequent presses of the H key, you do not see it. However, there is this input pin over here where I can reset it and make it so that after I press it, I can allow it to go again. So what I could do here off of my print string node is add what is called a delay node. And I could set this for a duration of, let's say, one second for five seconds, and then I'm going to drag a wire off of my completed and plug this back into my reset. So what I'm saying here is Once I press the H key, just one time, we will print the string that says done. And then after five seconds, I will be allowed to do it again.
So here we go. gonna hit play. Pressing H key shows the word done. Now if I press it again, nothing but if I wait five seconds, I believe five seconds has passed. I can press it again and it shows up. So that is a do one snowed in practice.
Next, let's go on to the flip flop node. So I'm going to delete this do once node out here. We don't need that guy. I'm going to delete out my delay. No, let's bring in the flip flop. Okay, what I'm going to do is hook it up.
Like this, and I'm going to duplicate my print string, select it Ctrl C to copy Ctrl V to paste. And I'm going to plug a into there and B into there. So what the flip flop node does is every time I press the H key is going to fire out the a branch first, then the B branch, then the Abraham branch, then the B branch, so every time I press it, it's going to select a different branch. Okay, so in this topmost one, I will type in the word flip, bottom node, I will type in flop, so it will alternate between those two words every time I tap the H key so here we go. Flip Flop, flip flop, flip flop, you get the point. Okay, next, let's go on to the sequence node.
Gonna delete out this flip flop node. Let's bring in the sequence node here. Now the sequence node comes in handy. Because there are certain events, such as Event Begin Play and Event Tick, that you can only have one copy of in your Event Graph. So what happens if you want multiple things to fire off of that one event? Well, what you can do is you can add a sequence node here, what a sequence node allows you to do is wire in one event, for example.
But then output as many signals as you want. It's kind of like splitting the signal. So what's going to happen here is I'm going to hook this in like this. Actually, I'm going to delete some of these, you can right click on these to remove execution pin. And I'm going to hook this one up here, and then this here, so the sequence node is going to fire off every thing in the list in a rapid succession. So fast in fact, it will seem simultaneously simultaneous So actually, let me add one more pin here.
And I'm going to Ctrl C and Ctrl V one more print string. So what I'll do is I'll change this to be a value of one up here, to right here, and three down below, instead. So now when I press the H key, I should see in the upper left hand corner, one, two and three appearing very rapidly. Okay, so pressing H key right now. There you go. Now the reason I saw it is 321, because it actually printed out 123.
It just kind of pushed the numbers on down the screen as I pressed it. Okay, so that's the sequence node, it will fire off everything in the list in rapid succession super fast that it will seem simultaneous. Just a couple more to explore here. Let's try out the gate node, shall we? I'm going to delete out our sequence. No, we don't need that anymore.
I'm going to delete out to print strings. I'm going to bring In a gate node. So with a gate node, you can actually determine if the flow of execution here is open or closed, we can enter into this pressing the H key will enter into this gate. But for starters, it is not going to be open. So I'm just gonna type into our print string over here, gate. Gate is now open.
Okay, but this node right here says by default, we are starting close. So if I press the H key will enter into this, but again, is currently closed. And so this will never fire. So I'm just going to jump in and play. And I'm going to tap that H key. And you'll see we don't get that text printed.
Because we have not opened the gate we need something to open the gate to allow this print string to display on screen. So what I'm going to do here Here is hooked up the releasing of the H key to open the gate. So what will happen is I'm going to press the H key, we're going to enter this gate, it's going to start off close because it starts off close, nothing will happen. But as soon as I release the H key, the gate will then be open. And so on my next press after that my second press of the H key, we will fire out of this execution pin and this string will be printed. So let's give it a try pressing the H key once don't do anything, releasing the H key so the gate is now open.
And I'll pressing the H key again. The gate is now open. So that is the gate node next one last one, in fact, will be switched on in so I'm going to delete this out. Let's bring in our switch switch on int node right here. gonna hook this in like this in just like our secret snowed are switched on in Node allows us to add some pins. So let's click on a couple right here.
Let's add a couple. And what I'm going to do is I'm going to copy and paste a string here. Let's hook these guys up like this. I'm going to call this one string number one. And this one is going to be called string number two. So what the switch on it allows us to do is it allows us to fire out of whichever execution pin is within this numbered box right here.
So in this case, if I press the H key, it's going to select pin number zero to fire out of not one. So once I jump in, it should press it should print string number one to the screen as soon as I press the H key. So let's give this a try. I'm pressing the H key and it shows string number one now I change this selection to be number one will now press the H key in, it'll fire out of this one branch right here, this one pin, which, which should print string number two. There you go. And you can add as many of these as you want.
This is a really good way to create a randomize a randomized system of sorts. For example, I've got five pins out here, what I could do is I could drag out of this guy right here, and I could look for a node called random integer in range. And what I can do is I can specify a min value of zero and a max number of, say, four. So what I'm telling the switch on int node to do here is to pick a number between zero and four and then fire out of whichever number it picks. So I wanted to skew the odds here. So that string number one is Printed four out of five times 80% of the time and 20% of the time it prints out string number two, I could have a setup such as this so let's give this a play and press the H key one time it chooses string number one, that time is chose string number two, just spamming the HQ now so you can see the results.
And that is what is switch on node is used for. Alright, so that's going to cover it for flow control nodes. We will see you guys in the next one