[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.84,0:00:05.15,Default,,0000,0000,0000,,And we're back! This time, our program has the Winston object, Dialogue: 0,0:00:05.15,0:00:10.02,Default,,0000,0000,0000,,but we're only displaying the age of Winston. That's because I wanna show Dialogue: 0,0:00:10.02,0:00:13.72,Default,,0000,0000,0000,,you how we could change Winston's age. Because you know eventually, Dialogue: 0,0:00:13.72,0:00:18.08,Default,,0000,0000,0000,,Winston has to get older. Let's remember what it would be like if we were Dialogue: 0,0:00:18.08,0:00:22.70,Default,,0000,0000,0000,,just using simple variables. We have var winston age equals 19, and then if we Dialogue: 0,0:00:22.70,0:00:27.09,Default,,0000,0000,0000,,wanted to change it, we would say winston age equals 20. Dialogue: 0,0:00:27.09,0:00:31.28,Default,,0000,0000,0000,,and that would change the value stored in that variable. It's really really similar Dialogue: 0,0:00:31.28,0:00:39.48,Default,,0000,0000,0000,,for object properties. We can just say winston dot age equals 20, and then we've changed Dialogue: 0,0:00:39.48,0:00:43.61,Default,,0000,0000,0000,,the value stored in the age property of the Winston object. Dialogue: 0,0:00:43.61,0:00:44.63,Default,,0000,0000,0000,,Cool. Dialogue: 0,0:00:44.63,0:00:48.57,Default,,0000,0000,0000,,So let's see if that worked. We'll take our text command, put it below, Dialogue: 0,0:00:49.06,0:00:54.02,Default,,0000,0000,0000,,change the y, tada! Winston got older. So easy. Dialogue: 0,0:00:54.54,0:00:59.32,Default,,0000,0000,0000,,Um, okay, so now let's try, we were just adding one here Dialogue: 0,0:00:59.32,0:01:07.31,Default,,0000,0000,0000,,let's do that more programatically. Let's say winston dot age equals winston dot age plus one. Dialogue: 0,0:01:07.31,0:01:10.86,Default,,0000,0000,0000,,So what we're saying here is take the previous value of his age Dialogue: 0,0:01:10.86,0:01:16.04,Default,,0000,0000,0000,,add one to it, and then store it in the age property. Dialogue: 0,0:01:16.90,0:01:21.79,Default,,0000,0000,0000,,And that should just end up adding one to whatever the previous value was. Let's see. Dialogue: 0,0:01:22.96,0:01:25.64,Default,,0000,0000,0000,,Display it, tada! He's 21. Dialogue: 0,0:01:25.64,0:01:30.06,Default,,0000,0000,0000,,Getting getting so old. All right. Now, remember we have a shortcut for adding one Dialogue: 0,0:01:30.06,0:01:36.80,Default,,0000,0000,0000,,to variables, and the same shortcut works with object properties so we can say winston dot age plus plus Dialogue: 0,0:01:37.56,0:01:44.100,Default,,0000,0000,0000,,And let's see if that worked. Yup! And that really just did exactly the same thing as this line, Dialogue: 0,0:01:44.100,0:01:49.14,Default,,0000,0000,0000,,it's just a shortcut, so that we don't have to type as much. Dialogue: 0,0:01:49.14,0:01:53.33,Default,,0000,0000,0000,,Now if we look at all this, this really looks like the situation for a loop. Dialogue: 0,0:01:53.33,0:01:57.79,Default,,0000,0000,0000,,We keep on using the same code over and over, and the only thing we're changing is we're adding one Dialogue: 0,0:01:57.79,0:02:02.53,Default,,0000,0000,0000,,to his age, and we're changing the y position so it's on a different line. Dialogue: 0,0:02:03.02,0:02:07.07,Default,,0000,0000,0000,,So, if we used a loop, it could be really easy to show him getting older and older and older Dialogue: 0,0:02:07.07,0:02:13.50,Default,,0000,0000,0000,,and not have to use that much code. Let's say, we'll make a loop to show Winston getting to 40 years old. Dialogue: 0,0:02:13.50,0:02:16.21,Default,,0000,0000,0000,,He doesn't wanna get any older than that because then he'd be wrinkly Dialogue: 0,0:02:16.26,0:02:19.25,Default,,0000,0000,0000,,and we'd have to call him "Wrinkleston." [laugh] Dialogue: 0,0:02:19.25,0:02:20.32,Default,,0000,0000,0000,,All right. Dialogue: 0,0:02:20.32,0:02:27.50,Default,,0000,0000,0000,,So we'll do a while loop and we'll say while winston dot age is less than or equal to 40 Dialogue: 0,0:02:27.50,0:02:32.24,Default,,0000,0000,0000,,and then inside here, we're gonna display his age Dialogue: 0,0:02:32.24,0:02:37.59,Default,,0000,0000,0000,,and we're going to add one to his age each time. Dialogue: 0,0:02:37.59,0:02:42.11,Default,,0000,0000,0000,,Okay, that worked, but everything is piled on top of each other, so we need to change the y position Dialogue: 0,0:02:42.11,0:02:53.25,Default,,0000,0000,0000,,each time. And we'll just do winston dot age times 20, um, minus 200, minus 300 Dialogue: 0,0:02:53.25,0:03:03.47,Default,,0000,0000,0000,,Okay! and we'll just minus 350. All right. That looks good. Let's delete the old stuff here. Dialogue: 0,0:03:03.47,0:03:10.28,Default,,0000,0000,0000,,Tada! Now we can see Winston getting older and older, but not so old that he'll be a Wrinkleston. Dialogue: 0,0:03:10.28,0:03:16.42,Default,,0000,0000,0000,,Okay. So, now we can see how to change age, we can also add additional information in the Dialogue: 0,0:03:16.42,0:03:22.14,Default,,0000,0000,0000,,Winston object as he gets older. Like, maybe when he turns 30, he'll meet another programmer Dialogue: 0,0:03:22.14,0:03:24.84,Default,,0000,0000,0000,,named Winnefer, and he'll marry her. Dialogue: 0,0:03:24.84,0:03:28.98,Default,,0000,0000,0000,,And no, he's not just gonna marry her because she has such a great name. Dialogue: 0,0:03:28.98,0:03:33.86,Default,,0000,0000,0000,,So what we can do is we can add a property by just saying winston dot, and then the new Dialogue: 0,0:03:33.86,0:03:39.34,Default,,0000,0000,0000,,property key which will be wife, equals Winnefer. Dialogue: 0,0:03:39.34,0:03:44.04,Default,,0000,0000,0000,,Great, but, we only want him to have this wife when he's at, you know, at a good marrying age Dialogue: 0,0:03:44.04,0:03:53.14,Default,,0000,0000,0000,,so we'll say equals 30 and we'll go and move, move that inside here. Dialogue: 0,0:03:53.14,0:03:57.76,Default,,0000,0000,0000,,Great. So now he has a wife, so, you know, they're happy, and then they have some kids Dialogue: 0,0:03:57.76,0:04:04.20,Default,,0000,0000,0000,,a couple years later, so maybe when they're, uh, 32, we'll add some kids to the object Dialogue: 0,0:04:04.20,0:04:08.20,Default,,0000,0000,0000,,to keep track of that. And they have twins, of course, cause they're very productive Dialogue: 0,0:04:08.20,0:04:16.87,Default,,0000,0000,0000,,And Winston's twins will be named, uh, of course Winston Junior and Winstonia. Dialogue: 0,0:04:16.87,0:04:21.85,Default,,0000,0000,0000,,Beautiful. That's a, that's a great family. Great set of names. Dialogue: 0,0:04:21.85,0:04:25.40,Default,,0000,0000,0000,,And so you can see we can add new properties that are strings and arrays Dialogue: 0,0:04:25.40,0:04:28.52,Default,,0000,0000,0000,,and anything we could've had in the original object. Dialogue: 0,0:04:28.52,0:04:33.53,Default,,0000,0000,0000,,And so once this loop finishes, winston dot age will be 40, and winston will Dialogue: 0,0:04:33.53,0:04:41.10,Default,,0000,0000,0000,,have a wife, who's Winnefer, and a twins, which is a set of er, which an array of two names. Dialogue: 0,0:04:41.10,0:04:45.94,Default,,0000,0000,0000,,Huh. That's an awesome loop. But, hey, if you don't like how this story ends for Winston, Dialogue: 0,0:04:45.94,0:04:50.18,Default,,0000,0000,0000,,you could always spin off this program and tell your own story of his future Dialogue: 0,0:04:50.18,0:04:53.73,Default,,0000,0000,0000,,now that you know all about how to change object properties.