[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:01.24,0:00:04.40,Default,,0000,0000,0000,,You already learned about using variables \Nto store numbers or strings. Dialogue: 0,0:00:04.40,0:00:06.24,Default,,0000,0000,0000,,Now we're going to learn \Nabout something called arrays, Dialogue: 0,0:00:06.24,0:00:09.68,Default,,0000,0000,0000,,which let us store multiple items \Nin just one variable. Dialogue: 0,0:00:09.68,0:00:12.98,Default,,0000,0000,0000,,As you'll see, arrays let us do \Nall kinds of useful things. Dialogue: 0,0:00:12.98,0:00:14.62,Default,,0000,0000,0000,,Okay, let's review variables. All right? Dialogue: 0,0:00:14.62,0:00:18.53,Default,,0000,0000,0000,,So we have, {\i1}var myFriend = "Sophia"{\i0}. Dialogue: 0,0:00:19.76,0:00:22.64,Default,,0000,0000,0000,,So, a variable is just a way \Nof storing a value, like Sofia, Dialogue: 0,0:00:22.64,0:00:26.60,Default,,0000,0000,0000,,and giving it a label so our program \Nhas an easy way to refer to it later. Dialogue: 0,0:00:26.60,0:00:28.11,Default,,0000,0000,0000,,We can think of it like a drawer, Dialogue: 0,0:00:28.11,0:00:32.39,Default,,0000,0000,0000,,with a {\i1}myFriend{\i0} label on the outside \Nand Sofia on the inside. Dialogue: 0,0:00:32.39,0:00:35.12,Default,,0000,0000,0000,,So whenever we look inside it, \Nwe find Sofia. Dialogue: 0,0:00:36.20,0:00:39.95,Default,,0000,0000,0000,,Now, sometimes we want to hold \Nmultiple values in a single variable Dialogue: 0,0:00:39.95,0:00:44.19,Default,,0000,0000,0000,,and we can't just do it like this\Nbecause we'll get a syntax error Dialogue: 0,0:00:44.19,0:00:46.27,Default,,0000,0000,0000,,and our program will freak out,\Nand all that stuff. Dialogue: 0,0:00:46.27,0:00:48.58,Default,,0000,0000,0000,,So we have a specific way\Nthat we do that, Dialogue: 0,0:00:48.58,0:00:50.57,Default,,0000,0000,0000,,and that's using arrays. Dialogue: 0,0:00:50.57,0:00:53.19,Default,,0000,0000,0000,,So we could say, {\i1}myFriends = {\i0}, Dialogue: 0,0:00:53.19,0:00:55.73,Default,,0000,0000,0000,,and then we have to do \Na square bracket, Dialogue: 0,0:00:55.73,0:00:58.60,Default,,0000,0000,0000,,and then inside, \Nthat's where we can put all the values. Dialogue: 0,0:00:58.60,0:01:03.72,Default,,0000,0000,0000,,So we say, Sofia, \Nand we have John, and we have Leif. Dialogue: 0,0:01:03.72,0:01:06.34,Default,,0000,0000,0000,,All right, so those are my three friends. Dialogue: 0,0:01:06.34,0:01:09.38,Default,,0000,0000,0000,,Maybe in order of how much I like them, \Nbut don't tell them that. Dialogue: 0,0:01:09.38,0:01:12.98,Default,,0000,0000,0000,,Okay, so now our variable \Nholds three values, not just one. Dialogue: 0,0:01:12.98,0:01:15.19,Default,,0000,0000,0000,,And we can imagine \Nit's like a chest of drawers, Dialogue: 0,0:01:15.19,0:01:18.19,Default,,0000,0000,0000,,and we put this label, {\i1}myFriends{\i0}, \Non the whole chest. Dialogue: 0,0:01:18.19,0:01:20.37,Default,,0000,0000,0000,,And we can just open the right drawer Dialogue: 0,0:01:20.37,0:01:22.67,Default,,0000,0000,0000,,to find the value \Nwe're looking for, right? Dialogue: 0,0:01:23.69,0:01:24.88,Default,,0000,0000,0000,,And you imagine, with a chest of drawers, Dialogue: 0,0:01:24.88,0:01:27.74,Default,,0000,0000,0000,,if you want to know \Nwhat's inside the first drawer, Dialogue: 0,0:01:27.74,0:01:29.78,Default,,0000,0000,0000,,you would just open it up and look inside. Dialogue: 0,0:01:29.78,0:01:31.95,Default,,0000,0000,0000,,So how do we do that with our array? Dialogue: 0,0:01:31.95,0:01:34.37,Default,,0000,0000,0000,,Well, we can just type \Nthe name of the array, Dialogue: 0,0:01:34.37,0:01:36.10,Default,,0000,0000,0000,,and then the brackets again-- Dialogue: 0,0:01:36.10,0:01:37.54,Default,,0000,0000,0000,,ooh, I misspelled it-- Dialogue: 0,0:01:39.43,0:01:42.65,Default,,0000,0000,0000,,and then the number \Nof whatever it is in the array, right? Dialogue: 0,0:01:42.65,0:01:45.46,Default,,0000,0000,0000,,So maybe it would be 1. Okay? Dialogue: 0,0:01:45.46,0:01:46.67,Default,,0000,0000,0000,,So, let's actually try this out Dialogue: 0,0:01:46.67,0:01:50.87,Default,,0000,0000,0000,,by using the text command \Nand showing Sofia on the canvas. Dialogue: 0,0:01:50.87,0:01:55.12,Default,,0000,0000,0000,,So we say, {\i1}myFriends{\i0}--\Nooh, friend is a hard word to spell, huh? Dialogue: 0,0:01:55.12,0:01:59.56,Default,,0000,0000,0000,,So, {\i1}myFriends[1]{\i0},\Nand then we put it here. Dialogue: 0,0:01:59.56,0:02:01.88,Default,,0000,0000,0000,,Oh, and then let's put a little fill. Dialogue: 0,0:02:01.88,0:02:06.27,Default,,0000,0000,0000,,Oh, okay, so we see John. \NWhy do we see John? Dialogue: 0,0:02:06.27,0:02:09.37,Default,,0000,0000,0000,,We said 1 for the element index, right? Dialogue: 0,0:02:09.37,0:02:11.18,Default,,0000,0000,0000,,The 1 right here. Dialogue: 0,0:02:11.18,0:02:15.51,Default,,0000,0000,0000,,Well, that's because \Narrays start at 0, not 1, Dialogue: 0,0:02:15.51,0:02:19.83,Default,,0000,0000,0000,,and it'll definitely seem weird at first,\Nbut you'll get used to it. Dialogue: 0,0:02:19.83,0:02:24.08,Default,,0000,0000,0000,,So if we put 0, \Nthen we see Sofia, all right? Dialogue: 0,0:02:24.08,0:02:26.12,Default,,0000,0000,0000,,And then, if we want to show \Nthe next element, Dialogue: 0,0:02:26.12,0:02:27.75,Default,,0000,0000,0000,,then we use 1, all right? Dialogue: 0,0:02:27.75,0:02:30.16,Default,,0000,0000,0000,,So, and then if we want to do \Nthe final element, Dialogue: 0,0:02:30.16,0:02:32.47,Default,,0000,0000,0000,,the third element, then we use 2. Dialogue: 0,0:02:33.05,0:02:36.62,Default,,0000,0000,0000,,So you just think to yourself:\N"Okay, which one do I want to retrieve?"-- Dialogue: 0,0:02:36.62,0:02:38.27,Default,,0000,0000,0000,,Oh, let's spread these out-- Dialogue: 0,0:02:38.27,0:02:41.30,Default,,0000,0000,0000,,and where is it located, \Nand you just subtract one. Dialogue: 0,0:02:41.30,0:02:43.74,Default,,0000,0000,0000,,So the first one is 0, \Nthe second one is 1, Dialogue: 0,0:02:43.74,0:02:46.90,Default,,0000,0000,0000,,the third one is 2, et cetera, et cetera. Dialogue: 0,0:02:46.90,0:02:51.93,Default,,0000,0000,0000,,What happens if I forgot, \Nand I try to access Leif this way? Dialogue: 0,0:02:51.93,0:02:55.92,Default,,0000,0000,0000,,Well then, we say {\i1}myFriends[3]{\i0}, \Nand we'll just get nothing. Dialogue: 0,0:02:55.92,0:02:58.49,Default,,0000,0000,0000,,That's because there's nothing there, right? Dialogue: 0,0:02:58.49,0:03:02.15,Default,,0000,0000,0000,,When it says 3, \Nit looks for the fourth element, Dialogue: 0,0:03:02.15,0:03:05.43,Default,,0000,0000,0000,,and there's no fourth element,\Nso there's just nothing. Dialogue: 0,0:03:05.43,0:03:07.65,Default,,0000,0000,0000,,And that's something that can happen a lot\Nwhen you're using arrays, Dialogue: 0,0:03:07.65,0:03:09.70,Default,,0000,0000,0000,,so just look out for that. Dialogue: 0,0:03:09.70,0:03:12.04,Default,,0000,0000,0000,,And the same thing \Nif I tried to access a hundred Dialogue: 0,0:03:12.04,0:03:15.43,Default,,0000,0000,0000,,because I don't have a hundred friends, \NI only have three, Dialogue: 0,0:03:15.43,0:03:19.13,Default,,0000,0000,0000,,so then we get nothing, all right? \NSo let's get rid of those. Dialogue: 0,0:03:19.13,0:03:21.77,Default,,0000,0000,0000,,Now, let's say we want to keep track \Nof how many friends we have Dialogue: 0,0:03:21.77,0:03:23.98,Default,,0000,0000,0000,,because I'm really proud,\Nand I have three friends, Dialogue: 0,0:03:23.98,0:03:25.72,Default,,0000,0000,0000,,and I want to let everybody know. Dialogue: 0,0:03:25.72,0:03:28.69,Default,,0000,0000,0000,,So I'm going to go \Nand declare this to the world. Dialogue: 0,0:03:28.69,0:03:32.51,Default,,0000,0000,0000,,So, {\i1}"I have " + numFriends + " friends!!!"{\i0}. Dialogue: 0,0:03:32.90,0:03:34.40,Default,,0000,0000,0000,,Woo, all right. Dialogue: 0,0:03:36.67,0:03:40.35,Default,,0000,0000,0000,,Okay, so I have three friends. Yay!\NOh, that's not very many. Dialogue: 0,0:03:40.35,0:03:43.99,Default,,0000,0000,0000,,Okay, so maybe Winston feels bad for me \Nand says he'll be my friend, Dialogue: 0,0:03:43.99,0:03:45.68,Default,,0000,0000,0000,,and he says I can add him to the array. Dialogue: 0,0:03:45.68,0:03:47.38,Default,,0000,0000,0000,,And I was like:\N"Okay, cool. Thanks, Winston." Dialogue: 0,0:03:47.38,0:03:48.84,Default,,0000,0000,0000,,So I add Winston. Dialogue: 0,0:03:48.84,0:03:50.96,Default,,0000,0000,0000,,Oh, but it still says \NI have three friends, right, Dialogue: 0,0:03:50.96,0:03:53.93,Default,,0000,0000,0000,,because I have to go \Nand update this variable here. Dialogue: 0,0:03:53.93,0:03:56.74,Default,,0000,0000,0000,,That means, every time \Nthat I add something to this array, Dialogue: 0,0:03:56.74,0:03:59.80,Default,,0000,0000,0000,,I have to update this variable, \Nand that could get really annoying, Dialogue: 0,0:03:59.80,0:04:01.44,Default,,0000,0000,0000,,especially if all of you guys \Nwatching this Dialogue: 0,0:04:01.44,0:04:03.43,Default,,0000,0000,0000,,decide you'll be my friend. Dialogue: 0,0:04:03.43,0:04:05.33,Default,,0000,0000,0000,,And then, you know, \NI'm updating this thousands of times Dialogue: 0,0:04:05.33,0:04:07.64,Default,,0000,0000,0000,,and having to update this every time. Dialogue: 0,0:04:07.64,0:04:09.10,Default,,0000,0000,0000,,So here's the thing: Dialogue: 0,0:04:09.10,0:04:13.68,Default,,0000,0000,0000,,We, so often, want to know \Nhow long our array is, Dialogue: 0,0:04:13.68,0:04:15.76,Default,,0000,0000,0000,,that there's a special way to do that. Dialogue: 0,0:04:15.76,0:04:18.14,Default,,0000,0000,0000,,So the array will keep track \Nof how long it is Dialogue: 0,0:04:18.14,0:04:20.09,Default,,0000,0000,0000,,using a property called {\i1}length{\i0}. Dialogue: 0,0:04:20.09,0:04:25.36,Default,,0000,0000,0000,,And to use it, we just say, \N{\i1}myFriends.length{\i0}, Dialogue: 0,0:04:25.36,0:04:26.76,Default,,0000,0000,0000,,and then we'll get back the length. Dialogue: 0,0:04:26.76,0:04:29.12,Default,,0000,0000,0000,,See, now it says 4, \Nand I can delete this variable. Dialogue: 0,0:04:29.12,0:04:30.53,Default,,0000,0000,0000,,I don't need it any more. Dialogue: 0,0:04:30.53,0:04:33.02,Default,,0000,0000,0000,,And this property will update \Nwhenever we add. Dialogue: 0,0:04:33.02,0:04:35.26,Default,,0000,0000,0000,,So maybe OhNoes Guy!! \Nsays he'll be my friend, and I'm like: Dialogue: 0,0:04:35.26,0:04:39.47,Default,,0000,0000,0000,,"Okay, you're kind of mean, \Nbut okay, you'll be my friend." Dialogue: 0,0:04:40.17,0:04:42.82,Default,,0000,0000,0000,,And we can keep adding\Nand it'll keep updating. Dialogue: 0,0:04:42.82,0:04:46.60,Default,,0000,0000,0000,,So, that's really cool because, you know, Dialogue: 0,0:04:46.60,0:04:49.60,Default,,0000,0000,0000,,it's a lot less work to keep track \Nof how long our array is. Dialogue: 0,0:04:49.60,0:04:50.86,Default,,0000,0000,0000,,All right, so pretty much, Dialogue: 0,0:04:50.86,0:04:53.54,Default,,0000,0000,0000,,whenever you want to store \Na list of values like this, Dialogue: 0,0:04:53.54,0:04:54.92,Default,,0000,0000,0000,,we'll use an array. Dialogue: 0,0:04:55.57,0:04:57.50,Default,,0000,0000,0000,,So keep watching to find out \Nall the really cool things Dialogue: 0,0:04:57.50,0:04:59.09,Default,,0000,0000,0000,,that we can use them for.