The good news is, that this module only has two lectures. And the even better news is, that we're going to use some really powerful ideas that we're going to find to be particularly useful in our game development. To start, here are the Module 9 learning objectives. So one of the things that we need to deal with as we develop games, is, we need to handle having a whole bunch of different game objects in the game world. And we've talked about, from way back in classes and objects, we talked about the optic oriented paradigm. And how it is a set of interacting objects in our software. Well our game world is a set of interacting entities and we need to do things with that set of interacting entities. We have to update all of them. We have to draw all of them. There are lots of things we need to do with all of the at least active entities in our game world. And having a separate variable that we use to store each of them is really problematic, that doesn't really work for us at all. We need a better way to store a whole bunch of game objects, and use those game objects within our world. That's what we're going to learn about in this module. So to start, you should take an in lecture quiz about arrays. So it turns out that arrays are a way that we can store a whole bunch of different objects. And so, it also turns out that arrays in C# are objects as well. And we'll see the syntax we use to deal with those array objects soon, but the question is, what can we store in arrays? And, the answer is, anything. We can store value types, we can store reference types, we can store other arrays in arrays, we can pretty much store anything we can think of. At least as a data type in the arrays that we have available to us in C#. That comes with a caution. Darn it, but there's always a but. The but is, that in a particular array, we can only store a single data type. So each array that we declare and use can only store one thing. So we can have an array on ints. And we could have an array of TeddyBears. And we could have an array of Texture2D's. And we could have an array of float. We can have each array, hold a different data type. But once we have an array, it can only store a single data type. So what do arrays look like in memory? Let's take a look. Conceptually, let's take a look. Before we do, do an in lecture quiz about arrays and what they can store, and then we'll look. Okay, so sort of conceptually, anyway, this is kind of like what arrays look like in memory. So think of all these floating point numbers as GPAs, or grade point averages that we're storing. So we have a variable called GPAs. And then, if we're storing ten of them, as in this example, then they're numbered. They're in memory boxes, as we're used to, but they're numbered from 0 to 9. And so, let's hit some terminology about how we talk about arrays and the things in arrays. So, do an in-lecture quiz about what each value that's stored in array is called. And because these in-lecture quizzes are often about joking around and being, I was going to say funny, being funny like I think funny is. it's possible that you don't actually know the right answer when you're done with this one. So the right answer is element. So each thing we store, we talk about an array of elements. So the thing at location zero is an array element, and the thing at location one is an array element and so on. So that the values that we're storing in the array are called elements, another end lecture quiz. The number we use to talk about the location in an array is called the index. So, zero is an index, and eight is an index. They're indexes into the array. Now, hopefully, you recall that you've heard this terminology before. We talked about indexes before, fairly recently, Module 7. Because we talked about accessing a particular character in a string by using the index of that character. We were actually ahead of the game we are actually accessing a particular item in an array by using an index. So that's why that terminology index was used there, and we will use it here too. So the index is a location in the array. So, let's go to the code we had before. This was mouse input processing, right? So, I press F5 to run the code, it follows me around, and I click to change the character. And, I only had four characters in this particular game. Oh, it is a game, I was interacting with it. in the game, but it could have been that I had hundreds of characters or something. We will see. Let's convert this to use an array instead of the four separate variables for the different character texture 2Ds. So I'm going to start here and instead of having these four variables, I'm going to declare a single variable that's an array. And the way I say it's an array, first I put the data type of the elements. This array is going to store texture to these. So that's what I put first. But then to tell the compiler I'm declaring an array variable, I put square brackets. Now, I put a variable name, I'm going to call these characters maybe, I'm going to call these characters and remember because arrays are objects. I'm going to need to create a new array. And I want to create a new array of Texture2Ds, but between the square brackets on this side, I need to say exactly how many elements I want. And in this particular case, I want four elements because I'm replacing four variables, semicolon. And that declares the array variable and creates the array object. Now, if I were to put the debugger right here, a break point, and get rid of that old break point I have hanging around. Let's stop. Let's try, [LAUGH], that again. We'll put the break-point here after all. If I F5, and now I look at this characters array I've hovered over, now I know it's hard to see. You can also, by the way, click around in here to expand what's in the character's array. Maybe that's easier to see. But you can see each of these four elements in the array is null right now. That's the default value for a reference type, is it starts at null. And so, even though I created the ray, array object, I didn't create all those characters in it. I'll F5 and get out of here. Get rid of that break point. Now, I'm going to delete these four variables, I don't need them anymore. I have this array instead, of course, that means, I don't compile anymore. Because down here, where I was trying to load those, right. I used to be loading into these four separate variables. Instead, I'm going to index into the array using the same notations we use to index to get a particular character from a string. And so I put the variable name square, open square bracket, the index I want to access and the closed square bracket. And of course I need the actual variable name characters, so that now I can compile. I'm still getting compilation errors and we'll fix those soon. But before we do, you should go do an in lecture quiz about accessing individual elements of the array. Now that you're back, let's finish that conversion to using the array. This is our next problem, and again, we'll just access characters zero instead. And so far, you might not see, be seeing a whole bunch of benefit, right? I mean, we did, in fact, reduce those four variables to one. And the rest of this, we haven't sort of done any reduction in code, or anything like that. Here's where we see a real win is here, when we're changing to a random character. So, we used to have all this code, to actually figure out what the next character was going to be. And I'm going to comment that out, and I'm going to say that the current character. Get set equal to some element of the character's array. And all I have to say is which index. But which index can be this random number that I generated between zero and three inclusive. So this single line of code does what all of this used to do before. And when I run the code again, I still am randomly getting different characters, with some duplicates, as we've discussed, and so on. So there's, there's a big benefit from using the arrays, I'll close out of here. There's a big benefit from using these arrays, because it let's us reduce the number of variables we have to have. And in some cases it significantly reduces the amount of code we need to have as well. We haven't even talked about it, but that array that we used here, was a one dimensional array. But arrays don't have to be one dimensional, they can have two dimensionals, for a game board, for example. If you were building a game of checkers, a two dimensional array would be a great way to save each space, what's in it, and so on. So, arrays don't have to be one dimensional. They can have numerous dimensions. And you should go do an in lecture quiz to tell me what you understand about that. Before I let you go, I thought you might like to see a little clip of how this array discussion goes in my regular classroom. So, at this point, I can tell I feel the energy pouring off of you guys. You guys are like, holy crap, what a tool. Now, I don't mean, okay wait a minute. [LAUGH]. >> [LAUGH]. No, no, don't look at me and think, what a tool. Think about arrays and say, what a tool, because now, now I can build games and if I'm going to have 400 teddy bears, I don't need 400 variables. Called teddy bear zero, teddy bear one, teddy bear two, teddy bear three. I can just build an array that will hold 400 teddy bears, and I just have to declare a variable once. And then you just, yay, hazzah, and there's much rejoicing. Okay, so we learned how to solve a core problem here. We learned how to store and use multiple different things all same data type, multiple different game entities so that we could efficiently use and process them. Next time, we're going to discover and even more robust way that we can store these multiple elements to overcome one of the core limitations of arrays. Say right now, the core limitation of the array is when we created the array object, we had to say how many elements there were going to be. And so if we have a game where we spawn elements or kill elements, game entities, excuse me, then arrays are harder to work with. So next time, we're going to learn about something called collection classes. That we can use to, basically use many of the same ideas that we get with arrays, but in a more robust way.