[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:01.33,0:00:03.80,Default,,0000,0000,0000,,I've written a program to tell you juicy details about Dialogue: 0,0:00:03.80,0:00:07.47,Default,,0000,0000,0000,,Winston, but not too much because Winston likes to keep some Dialogue: 0,0:00:07.47,0:00:11.87,Default,,0000,0000,0000,,mystery. That's just the Winston way. So, let's Dialogue: 0,0:00:11.87,0:00:15.33,Default,,0000,0000,0000,,see how I did this program. I created some variables at the top to store bits of Dialogue: 0,0:00:15.33,0:00:20.03,Default,,0000,0000,0000,,information about him. The first variable holds a number - his age - the second variable holds Dialogue: 0,0:00:20.03,0:00:23.96,Default,,0000,0000,0000,,a string - his eyes - the third variable holds an array of strings, Dialogue: 0,0:00:23.96,0:00:27.91,Default,,0000,0000,0000,,which are things he likes doing, and the last two variables hold Dialogue: 0,0:00:27.91,0:00:31.57,Default,,0000,0000,0000,,strings which describe where he was born. Then Dialogue: 0,0:00:31.57,0:00:35.94,Default,,0000,0000,0000,,down here, I wrote each of these out using the text command and just using the variable Dialogue: 0,0:00:35.94,0:00:39.70,Default,,0000,0000,0000,,name. And of course for the array, I have to access each element of the array Dialogue: 0,0:00:39.70,0:00:43.45,Default,,0000,0000,0000,,using bracket notation. Cool. Now, Dialogue: 0,0:00:43.45,0:00:48.64,Default,,0000,0000,0000,,all five of these variables are describing information about the same thing: Winston Dialogue: 0,0:00:48.64,0:00:51.60,Default,,0000,0000,0000,,But the variables don't know that they're about the same thing Dialogue: 0,0:00:51.60,0:00:55.50,Default,,0000,0000,0000,,And, you know, in Javascript, when you wanna Dialogue: 0,0:00:55.50,0:00:59.29,Default,,0000,0000,0000,,store multiple pieces of information that are related, we have a better way of Dialogue: 0,0:00:59.29,0:01:03.12,Default,,0000,0000,0000,,storing them that's really cool, and it's called an object. Dialogue: 0,0:01:03.12,0:01:06.80,Default,,0000,0000,0000,,So what it means is that instead of 5 variables, we can have a single Dialogue: 0,0:01:06.80,0:01:11.62,Default,,0000,0000,0000,,variable that stores all this information, which is pretty cool. Dialogue: 0,0:01:11.62,0:01:15.17,Default,,0000,0000,0000,,Let's try it out with Winston's information. First, we'll declare the Dialogue: 0,0:01:15.17,0:01:18.84,Default,,0000,0000,0000,,variable and we'll call it Winston. And then Dialogue: 0,0:01:18.84,0:01:23.40,Default,,0000,0000,0000,,we put an open curly bracket - make sure it's curly, not square - Dialogue: 0,0:01:23.40,0:01:27.11,Default,,0000,0000,0000,,and a semicolon. So we've created an object Dialogue: 0,0:01:27.11,0:01:31.05,Default,,0000,0000,0000,,but it has absolutely no information inside of it. Dialogue: 0,0:01:31.91,0:01:35.67,Default,,0000,0000,0000,,So, to add a bit of information, we need to add properties. Dialogue: 0,0:01:35.67,0:01:41.28,Default,,0000,0000,0000,,And each property is a key and a value. For example, age would be age: 19 Dialogue: 0,0:01:41.28,0:01:43.79,Default,,0000,0000,0000,,Okay. And then for eyes, we're gonna add a Dialogue: 0,0:01:43.79,0:01:48.04,Default,,0000,0000,0000,,comma, and then eyes: "black". Okay, cool, Dialogue: 0,0:01:48.04,0:01:52.74,Default,,0000,0000,0000,,so now Winston has two properties inside the object. Dialogue: 0,0:01:52.74,0:01:55.61,Default,,0000,0000,0000,,Uh, for likes, we can just go likes: and then I'll Dialogue: 0,0:01:55.61,0:02:00.08,Default,,0000,0000,0000,,just copy paste this from up here... and Dialogue: 0,0:02:00.08,0:02:04.00,Default,,0000,0000,0000,,very nice. So let's look at this. Winston has three properties Dialogue: 0,0:02:04.00,0:02:07.53,Default,,0000,0000,0000,,Every property has a key, which is what's on the right Dialogue: 0,0:02:07.53,0:02:12.80,Default,,0000,0000,0000,,hand side, and a value, which is what's on the left-hand side. Dialogue: 0,0:02:12.80,0:02:15.63,Default,,0000,0000,0000,,For the key, it should follow the same rules as Javascript Dialogue: 0,0:02:15.63,0:02:20.10,Default,,0000,0000,0000,,variable names. No spaces, start it with a letter, all that Dialogue: 0,0:02:20.59,0:02:22.96,Default,,0000,0000,0000,,For the value, it can be any type of value Dialogue: 0,0:02:22.96,0:02:27.12,Default,,0000,0000,0000,,we've seen so far. It could be number, it could be a string, it could be an array Dialogue: 0,0:02:27.12,0:02:33.37,Default,,0000,0000,0000,,It could even be a boolean, so we could add isCool: true, of course Dialogue: 0,0:02:34.13,0:02:38.40,Default,,0000,0000,0000,,In fact, the value could even be another object. So, Dialogue: 0,0:02:38.40,0:02:42.71,Default,,0000,0000,0000,,BirthCity and BirthState. Those really are bits of information about the same Dialogue: 0,0:02:42.71,0:02:46.62,Default,,0000,0000,0000,,thing, which is a single location. And, so I think it be make Dialogue: 0,0:02:46.62,0:02:51.04,Default,,0000,0000,0000,,more sense if we stored it as an object. I'll add another key, birthplace, Dialogue: 0,0:02:51.04,0:02:54.84,Default,,0000,0000,0000,,and then for the value I'm gonna put my curly brackets again Dialogue: 0,0:02:54.84,0:02:58.38,Default,,0000,0000,0000,,and then inside I'll have key for city, Dialogue: 0,0:02:58.38,0:03:02.29,Default,,0000,0000,0000,,"Mountain View", and then state, Dialogue: 0,0:03:02.29,0:03:06.77,Default,,0000,0000,0000,,"California". Great! So now you can see, you can really Dialogue: 0,0:03:06.77,0:03:10.48,Default,,0000,0000,0000,,store very rich information inside an object. Dialogue: 0,0:03:11.03,0:03:15.46,Default,,0000,0000,0000,,All right. So now that we have this nice object that describes all this information about Winston, Dialogue: 0,0:03:15.46,0:03:18.78,Default,,0000,0000,0000,,let's try deleting those old separate variables Dialogue: 0,0:03:18.78,0:03:23.07,Default,,0000,0000,0000,,that didn't know about each other. Okay Dialogue: 0,0:03:23.07,0:03:27.04,Default,,0000,0000,0000,,Um, uh oh! Uh so now we've got an error. And that's because our Dialogue: 0,0:03:27.04,0:03:30.74,Default,,0000,0000,0000,,text commands are referencing the old variables. We need to update Dialogue: 0,0:03:30.74,0:03:34.50,Default,,0000,0000,0000,,them to use information from the object instead. Let's Dialogue: 0,0:03:34.50,0:03:38.22,Default,,0000,0000,0000,,start with just commenting out the last three so that we can Dialogue: 0,0:03:38.22,0:03:41.87,Default,,0000,0000,0000,,do one at a time. Okay. So it says WinstonAge Dialogue: 0,0:03:41.87,0:03:46.40,Default,,0000,0000,0000,,right now. What we need to do is replace that, so we'll type Dialogue: 0,0:03:46.40,0:03:50.29,Default,,0000,0000,0000,,winston, cause that's the variable name. Notice if we Dialogue: 0,0:03:50.29,0:03:53.83,Default,,0000,0000,0000,,just leave it like that, it says object object. That's really Dialogue: 0,0:03:53.83,0:03:57.37,Default,,0000,0000,0000,,gross. That's Javascript telling us that we're trying to turn an entire Dialogue: 0,0:03:57.37,0:04:02.11,Default,,0000,0000,0000,,object into a string value. But instead, we really just Dialogue: 0,0:04:02.11,0:04:06.13,Default,,0000,0000,0000,,wanna access only the age inside of it. So what we do is we put a Dialogue: 0,0:04:06.13,0:04:11.06,Default,,0000,0000,0000,,dot, and then we write the property key, which is "age". Dialogue: 0,0:04:11.06,0:04:14.90,Default,,0000,0000,0000,,Tada! We have the age. We call this "dot notation," Dialogue: 0,0:04:14.90,0:04:18.28,Default,,0000,0000,0000,,which is where we write the variable name for the object, and then a dot, Dialogue: 0,0:04:18.28,0:04:21.79,Default,,0000,0000,0000,,and then the property key. Okay, so we can Dialogue: 0,0:04:21.79,0:04:26.24,Default,,0000,0000,0000,,go and do more now. Let's uncomment this, and then instead of Winston Dialogue: 0,0:04:26.24,0:04:29.88,Default,,0000,0000,0000,,eyes, we'll just say winston dot eyes, and then Dialogue: 0,0:04:29.88,0:04:34.07,Default,,0000,0000,0000,,for this one, it'll be winston dot likes, Dialogue: 0,0:04:34.07,0:04:37.74,Default,,0000,0000,0000,,and then winston dot likes one, and then Dialogue: 0,0:04:37.74,0:04:42.50,Default,,0000,0000,0000,,for this last one, it's a little more complicated because Dialogue: 0,0:04:42.50,0:04:45.45,Default,,0000,0000,0000,,it's an object inside an object. So we're gonna say Dialogue: 0,0:04:45.45,0:04:48.78,Default,,0000,0000,0000,,winston, and then dot, birthplace, Dialogue: 0,0:04:48.78,0:04:53.29,Default,,0000,0000,0000,,but if we do that it's still just the whole object so then we have to say dot, Dialogue: 0,0:04:53.29,0:04:57.46,Default,,0000,0000,0000,,city. Okay let's do this here... winston, Dialogue: 0,0:04:57.46,0:05:01.57,Default,,0000,0000,0000,,dot, birthplace, dot, state. Dialogue: 0,0:05:01.57,0:05:05.79,Default,,0000,0000,0000,,Tada! So it's really cool cause you can just reach down inside the objects Dialogue: 0,0:05:05.79,0:05:09.42,Default,,0000,0000,0000,,that are in the objects. All right Dialogue: 0,0:05:10.86,0:05:13.92,Default,,0000,0000,0000,,Awesome. So, as you can see, Dialogue: 0,0:05:13.92,0:05:17.60,Default,,0000,0000,0000,,objects are a great way to store a bunch of related bits Dialogue: 0,0:05:17.60,0:05:21.41,Default,,0000,0000,0000,,of information about an object, and then be able to access it later. Dialogue: 0,0:05:21.41,0:05:25.41,Default,,0000,0000,0000,,And when you keep going, you're gonna find out just how awesome objects are!