Well, we're moving onto the next module, where we're going to learn how we can make decisions in our programs. Here are the learning objectives for the module. So I said we're going to learn about how we can make decisions in our programs. So what kinds of decisions do we need to make? So, here are some examples. What does our program have to decide to do? We might decide, based on user input. Which direction we should move the player's avatar. So, for example, if they're using wasd, then you want to move up with w and left with a and so on. So movement based on user is one of the things we decide about. Another thing we decide about is Is the selection control structure. That's what it's called because we're selecting between multiple courses of action in our program. Okay. So we use the selection control structure to detect collisions and also we use it to resolve collisions. So the resolution of a collision may be based on a variety of different factors. Are we wearing enough armor that the rocket propelled grenade bounces off when the collision occurs? Or do we not have the level of protection so that something else happens when that collision occurs. Okay. players do stuff in games right? That's why they are fun to play and based on the players performance, say whether they are playing a mini game and they have to have a sort of a minimal bar of performance, we can use selection to decide whether they get, loot or not. So we might need to decide that. Players navigate menus in most games, and so based on their selection of which menu they want to go to, we might do that as well. By the way, menus? People do not get at all excited about writing menus. And virtually every single game you'll ever play has 'em. So it's one of the things that you'll end up doing as a game developer that is not nearly as exciting as some of the other things you do. You can actually build some interesting menu systems if you choose to do so. But. You know, you're going to have to build them. Just like tutorials, which has nothing to with the selection control structure but tutorials are another thing that people tend to not get too excited about but everyone builds into their games. And lots more. There's lots more stuff that you might need to do in terms of deciding how your game performs. So you should go take an in-lecture quiz, so that you can tell me about the statement we're going to look at today for doing that decision making. Okay, so this a graphical representation of the if statement. And this graphical representation is what's called a control flow graph because it graphs how the control flows through the program, eh, looks something like a flow chart for those of you who have heard of such things. We don't tend to use these things as design mechanisms anymore, but we do use them to help visualize. What the program will do. And so, let's pretend, because we're going to do it soon, let's pretend that we're going to ask the player for some input. We're going to ask them a yes or no question, and if they answer yes, we want to print an appropriate yes message. And so, this is sort of, a picture of how that flow through the program would work. We'll ask them the question. And then we'll check their response. Let's put it in a variable called answer. And we'll check their response to see if it's equal to Y for yes. And if it is we'll print that message. And if it's not we won't. So those things. Those edges, if you will, that come out of that top node are called branches. And so you should take and in-lecture quiz to tell me about what you understand about branches. And now you should go do another in-lecture quiz to tell me what you know about that answer equal equal yes part that we labeled the node with. So that expression the answer equal equal yes Is called a Boolean expression. Remember, Boolean variables can have values of true or false and a Boolean expression is merely an expression that evaluates to true or false and we use that result, the value it evaluates to decide whether or not we should do the thing. The branch, on the true side. Let's fire up the IDE, I already have a template built. Notice I remembered to zoom in this time, so we're going to look at some forms of the if statement and so, the first thing we're going to do is ask for and get. An input from the user to a yes or no question. So we know how to ask for, we do a prompt. [NOISE] And let's give them something interesting to answer about. Pick up the shiny thing, and we'll tell them, they should tell us either yes or no. So there's our prompt [NOISE] and then we're going to read this in. Now, this is a single character we're trying to read in so let's call it answer and I've declared it to be the char data type and of course, I try to do a console dot read line. And, I get a compilation error that says I can't implicitly convert a string to a char. I've specifically chosen to put this into a char for two reasons. First of all, the character is the right choice, right, they're picking something with the single character so we should in fact store it in the single character variable. The other reason I've decided to do it this way is because I wanted to show you that at this point after this call to Console.ReadLine we know we're holding a string of characters. A string in fact. A string object. And we also know that we can access particular characters in that string by indexing using the square brackets. So I wanted to show you that we can take this call to the method, and then add at the end, square bracket, zero, square bracket, and that will take that string object that the method returns, and index into it to extract the 0th character in the string. So now we're holding the answer, let's add that. Extra blank line that I like so much. [NOISE] And let's run it now before we add the if statement to make sure that's working properly. Pick up the shiny thing, yes or no. You'll notice that I can type a whole long thing here. And, it's just going to extract the d from the very beginning. We'll learn later that there are other ways that we could take care of this, but for now we're going to focus on the if statement so we're going to let that happen. And that's the read line, press any key to continue so I have. So, let's print an appropriate message. Let's print a message for the yes. So, this looks much like the control flow graph where Boolean expression between the parentheses here. So, if in fact the. Character that they, the first character of the string they enter is in fact a lower case y, then we'll print something. [NOISE] you have the shiny object. So, now let's test our code. So we're going to try it with, we want to go down the true branch. So we'll make sure we enter a lowercase y, and we want to go down the false branch from that picture which will imprint any message at all at this point. Okay, so let's run it, and I'll just enter y, and I get that you have the shiny object. I'll run it again, and enter anything other than y, like h. And I don't get that message. So that was the false branch. The only thing you might notice is that if I run this and I enter capital Y instead of lower case y. Because I've got caps lock on. Because cruise control for cool. Oh I don't get a message. And it feels like I should. Right, so there are a variety of ways that we can do this. We can make sure that the time we get to the if statement, we've capitalized or lower cased whatever character they entered, but I'd rather actually build a more complicated Boolean expression here, to show you how that works, so we're checking if answer equals lower case y here. And we learned that we have this or, Boolean operator, so we can check if it's lowercase y or, uppercase y. And so that way when I Ctrl+F5, we'll try all three again. Y still works the way it should've. H still works the way it should've, but now when I enter a capital I, I get that message again. So, we've looked at the first former variant of an if statement where we just have the if clause, or the if block, this part right here. And we've built a, not really complicated but more complicated than just testing one thing, Boolean expression. So let's go back to the slides and look at another form where in fact, if they say no. We can do something else. So at this point we have both a Print yes message along the true branch. And a Print no message along the false branch. So this is a pictorial representation of an If statement that has an Else clause in it. So now we add the code for that. And we add the code, by saying else. And we'll write now, whoops, sorry [LAUGH]. Something really compelling, you don't have the shiny object. So now we have an if statement that will do this part. If the Boolean expression of that leads to true. And if the Boolean expression of that leads to false it will go do this part. So when we Ctrl+F5, I'll test y again. And I'll test n. Oh, good that's what it should have done. However, you might also realize that if we enter H, we still get, you don't have the shiny object. And that maybe acceptable for what we're writing right now, however, lets actually be, we're tired, we're tired of the use of being a dork and so we want to be a little abusive if they don't pick yes or no. other than being mean to the you, player, there's a good reason for this because it lets me show you one more piece of the if statement. So let's actually say that we want the else to be something mean. You are a noob. And here we want to print the no message. What we can do is we can add an else if, [SOUND] and I will check both lowercase n, and uppercase N [NOISE] like so. [NOISE] And here's where we'll write, you don't have the shiny object. So thinking about how this will work. What happens is when we're running this code we get to this point right here. And we check the Boolean expression. If this Boolean expression evaluates to true it will print this line. And then it goes all the way down here. So it goes all the way past this very last curly brace. If this evaluates to a false, it goes down and checks at this one. And if this one evaluates to a true, it does this, and then comes all the way past the whole if statement. If neither this nor this evaluated to true, it'll come to the else and tell the user they are a noob. Let's try it. I pressed F5 and I crashed it because I just hit Enter because the user is in fact a moron. So let me do Ctrl+F5, we'll check yes. Yes, works fine. [SOUND] We'll check both lowercase n, oh, dear. It says, we're a noob. So now we have this debugging thing. Right? We have to go look at this Boolean expression and say, what's going wrong? And if we look at this Boolean expression we can see that in my frenzy of typing, I said for this Boolean expression, if the answer is, this is an and not an or, I said if the answer is both lower case and uppercase n, and that is, in fact, impossible. So, this should have been an or. See, even in a well-polished well-prepared lecture, there can be mistakes, just like programming happens in general. That's why we're testing it. Okay, so, I'll try the lower case n, you don't have the shiny object, I'll try the upper case N, you don't have the shiny object and finally I'll try my, my favorite not search for something, I'll try my favorite h. And, I am, in fact, a noob. So, that's it for the sort of different variance of the if statement, we looked at three different ways we could use this. We looked at and if that just has a true branch and nothing on the false branch We looked at the if else, which has both true and false branches, and then we looked at adding else ifs, as well. In case we have a more complicated sequence of Boolean expressions that we want to test. You should know, once we start adding else ifs, we can add as many else ifs if we want, as we want. And, the else part is in fact, option, we can just have if, else, if and that's it and it will be exactly as you'd expect. Next time, we're going to look. So that's it for today, next time we're going to look at another statement in C# that we can use to make decisions in our programs.