[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:01.48,0:00:04.18,Default,,0000,0000,0000,,Here's a function\Nyou might not know about: random. Dialogue: 0,0:00:04.18,0:00:07.34,Default,,0000,0000,0000,,It takes in two parameters:\Na lower bound and an upper bound, Dialogue: 0,0:00:07.34,0:00:10.59,Default,,0000,0000,0000,,and it gives you back a random number\Nsomewhere between those two bounds. Dialogue: 0,0:00:10.59,0:00:14.39,Default,,0000,0000,0000,,So here, this variable number will be\Nsomewhere between zero and one. Dialogue: 0,0:00:14.39,0:00:18.15,Default,,0000,0000,0000,,Then we're going to draw that number\Nto the canvas using this {\i1}text{\i0} function. Dialogue: 0,0:00:18.15,0:00:21.87,Default,,0000,0000,0000,,Those last two parameters are\Nfor the x and y coordinates of the text Dialogue: 0,0:00:21.87,0:00:25.56,Default,,0000,0000,0000,,and we use {\i1}textSize{\i0} and {\i1}fill{\i0}\Nto set the fill and the color of the text. Dialogue: 0,0:00:25.56,0:00:27.100,Default,,0000,0000,0000,,So if I press {\i1}Restart{\i0} a couple of times, Dialogue: 0,0:00:27.100,0:00:30.24,Default,,0000,0000,0000,,you can see the random numbers\Nbeing generated, Dialogue: 0,0:00:30.24,0:00:33.63,Default,,0000,0000,0000,,and you'll see the precision of\Nthese numbers is to three decimal places. Dialogue: 0,0:00:33.63,0:00:35.10,Default,,0000,0000,0000,,So here's a question-- Dialogue: 0,0:00:35.10,0:00:38.36,Default,,0000,0000,0000,,what if I only wanted to generate\Na number that's either zero or one? Dialogue: 0,0:00:38.36,0:00:41.79,Default,,0000,0000,0000,,Well, we can use\Nthis other function called {\i1}round{\i0}, Dialogue: 0,0:00:41.79,0:00:45.75,Default,,0000,0000,0000,,and this takes in a number that can\Nhave as many decimals as you want, Dialogue: 0,0:00:45.75,0:00:47.92,Default,,0000,0000,0000,,and it rounds it to the nearest integer. Dialogue: 0,0:00:47.92,0:00:51.83,Default,,0000,0000,0000,,So I'm just going to go ahead\Nand make a new variable called {\i1}integer{\i0} Dialogue: 0,0:00:51.83,0:00:53.92,Default,,0000,0000,0000,,and assign it whatever round gives us. Dialogue: 0,0:00:53.92,0:00:55.97,Default,,0000,0000,0000,,We can also draw that integer\Nto the screen Dialogue: 0,0:00:55.97,0:00:58.17,Default,,0000,0000,0000,,with our handy-dandy {\i1}text{\i0} function. Dialogue: 0,0:00:58.17,0:01:00.38,Default,,0000,0000,0000,,So {\i1}text(integer{\i0} Dialogue: 0,0:01:00.38,0:01:06.24,Default,,0000,0000,0000,,--we'll put it maybe at 160\Nand 350. Nice. Dialogue: 0,0:01:06.24,0:01:12.12,Default,,0000,0000,0000,,So this shows us that round of 0.2314\Nrounds down to zero, Dialogue: 0,0:01:12.12,0:01:18.01,Default,,0000,0000,0000,,and if I put in something like 4.6,\Nthat would round me up to 5. Neat. Dialogue: 0,0:01:18.01,0:01:20.59,Default,,0000,0000,0000,,So if I wanted to randomly generate\Na zero or a one, Dialogue: 0,0:01:20.59,0:01:24.26,Default,,0000,0000,0000,,I can take this random decimal\Nthat we're generating, Dialogue: 0,0:01:24.26,0:01:27.37,Default,,0000,0000,0000,,that falls between zero and one, Dialogue: 0,0:01:28.01,0:01:30.60,Default,,0000,0000,0000,,and stick it right into\Nthat {\i1}round{\i0} function. Dialogue: 0,0:01:30.60,0:01:32.99,Default,,0000,0000,0000,,So just like this:\NI'm going to grab this number Dialogue: 0,0:01:32.99,0:01:35.41,Default,,0000,0000,0000,,and plop it down here. Dialogue: 0,0:01:35.41,0:01:37.01,Default,,0000,0000,0000,,And now you can see Dialogue: 0,0:01:37.01,0:01:39.54,Default,,0000,0000,0000,,that whenever we generate\Na number that's less than 0.5, Dialogue: 0,0:01:39.54,0:01:41.35,Default,,0000,0000,0000,,it gets rounded down to zero, Dialogue: 0,0:01:41.35,0:01:44.78,Default,,0000,0000,0000,,and whenever we generate a number\Nthat is greater than or equal to 0.5, Dialogue: 0,0:01:44.78,0:01:46.75,Default,,0000,0000,0000,,it gets rounded up to one. Dialogue: 0,0:01:47.60,0:01:51.32,Default,,0000,0000,0000,,Maybe you can start to see the beginning\Nof some sort of coin-flip game here Dialogue: 0,0:01:51.32,0:01:54.92,Default,,0000,0000,0000,,where if you flip a zero,\Nyour friend gives you a dollar, Dialogue: 0,0:01:54.92,0:01:57.59,Default,,0000,0000,0000,,and if you flip a one,\Nyour friend gives you ten dollars. Dialogue: 0,0:01:57.59,0:01:58.73,Default,,0000,0000,0000,,Great game, right? Dialogue: 0,0:01:58.73,0:02:01.54,Default,,0000,0000,0000,,In fact, let's go ahead\Nand illustrate this coin-flipping game Dialogue: 0,0:02:01.54,0:02:03.33,Default,,0000,0000,0000,,with some super realistic coins Dialogue: 0,0:02:03.33,0:02:06.09,Default,,0000,0000,0000,,that just happen to look\Nlike really boring ellipses. Dialogue: 0,0:02:06.09,0:02:10.60,Default,,0000,0000,0000,,Just like this: I'm going to draw\Nan ellipse in the middle of our canvas Dialogue: 0,0:02:10.60,0:02:12.29,Default,,0000,0000,0000,,and that's going to be our coin. Dialogue: 0,0:02:12.29,0:02:15.28,Default,,0000,0000,0000,,Ooh! It's covering the text.\NLet's scoot that up a bit. Dialogue: 0,0:02:16.77,0:02:20.71,Default,,0000,0000,0000,,Great, and I have this idea\Nwhere, if I flip a zero, Dialogue: 0,0:02:20.71,0:02:23.25,Default,,0000,0000,0000,,I'm going to show\Nthe purple side of the coin, Dialogue: 0,0:02:23.25,0:02:28.08,Default,,0000,0000,0000,,so to make the coin purple,\NI can just fill it with some purple. Dialogue: 0,0:02:28.74,0:02:32.95,Default,,0000,0000,0000,,If I flip a 1,\NI'll show the yellow side of the coin Dialogue: 0,0:02:32.95,0:02:35.31,Default,,0000,0000,0000,,so it'll be a purple\Nand yellow-sided coin. Dialogue: 0,0:02:35.31,0:02:37.78,Default,,0000,0000,0000,,And luckily, with our impressive\Nknowledge of if-statements Dialogue: 0,0:02:37.79,0:02:39.33,Default,,0000,0000,0000,,this is super easy. Dialogue: 0,0:02:39.33,0:02:44.57,Default,,0000,0000,0000,,We can just say if integer equals zero, Dialogue: 0,0:02:44.57,0:02:48.22,Default,,0000,0000,0000,,(remember we use\Nthree equals signs to check for equality), Dialogue: 0,0:02:48.22,0:02:53.11,Default,,0000,0000,0000,,then we will fill the ellipse purple. Dialogue: 0,0:02:53.54,0:02:57.64,Default,,0000,0000,0000,,Then, if integer is equal to one, Dialogue: 0,0:02:58.87,0:03:01.12,Default,,0000,0000,0000,,we have a different fill function Dialogue: 0,0:03:02.28,0:03:04.34,Default,,0000,0000,0000,,and we'll make that one yellow. Dialogue: 0,0:03:06.30,0:03:09.43,Default,,0000,0000,0000,,Great. And it works! Woo hoo! Dialogue: 0,0:03:09.43,0:03:11.41,Default,,0000,0000,0000,,But let's think about this for a second-- Dialogue: 0,0:03:11.41,0:03:14.25,Default,,0000,0000,0000,,{\i1}integer{\i0} here will only ever\Nbe zero or one, right? Dialogue: 0,0:03:14.25,0:03:15.77,Default,,0000,0000,0000,,We designed it that way Dialogue: 0,0:03:15.77,0:03:18.93,Default,,0000,0000,0000,,so that means\Nthat either this statement will be true, Dialogue: 0,0:03:18.93,0:03:21.20,Default,,0000,0000,0000,,or this statement will be true Dialogue: 0,0:03:21.20,0:03:22.29,Default,,0000,0000,0000,,Always. Dialogue: 0,0:03:22.29,0:03:24.68,Default,,0000,0000,0000,,We've covered every possible case here, which means Dialogue: 0,0:03:24.68,0:03:27.67,Default,,0000,0000,0000,,we can start thinking about\Nour decision-making a little differently. Dialogue: 0,0:03:27.67,0:03:32.37,Default,,0000,0000,0000,,That is, if integer is equal to zero,\Nwe will fill it purple, Dialogue: 0,0:03:33.02,0:03:35.30,Default,,0000,0000,0000,,otherwise, we'll fill yellow. Dialogue: 0,0:03:35.93,0:03:38.24,Default,,0000,0000,0000,,So, do you see\Nhow we don't have to say anything Dialogue: 0,0:03:38.24,0:03:40.59,Default,,0000,0000,0000,,about integer being one\Nin that second case? Dialogue: 0,0:03:40.59,0:03:41.80,Default,,0000,0000,0000,,All we have to say is, Dialogue: 0,0:03:41.80,0:03:44.88,Default,,0000,0000,0000,,"If integer is zero, do this;\Notherwise, do that", Dialogue: 0,0:03:44.88,0:03:47.98,Default,,0000,0000,0000,,and, in programming,\Nthe way we say "otherwise" is "else." Dialogue: 0,0:03:47.98,0:03:49.24,Default,,0000,0000,0000,,So watch this: Dialogue: 0,0:03:49.24,0:03:53.10,Default,,0000,0000,0000,,I'm just going to replace this second\Nif-condition with the word "else" Dialogue: 0,0:03:53.10,0:03:54.62,Default,,0000,0000,0000,,and what this means is, Dialogue: 0,0:03:54.62,0:03:57.53,Default,,0000,0000,0000,,if the stuff inside these parentheses\Nis true, Dialogue: 0,0:03:57.53,0:03:59.65,Default,,0000,0000,0000,,then run the code in these brackets. Dialogue: 0,0:03:59.65,0:04:02.43,Default,,0000,0000,0000,,Otherwise, run the code in {\i1}these{\i0} brackets. Dialogue: 0,0:04:02.80,0:04:06.26,Default,,0000,0000,0000,,Sometimes we'll even put the "else"\Non the same line as that closing bracket Dialogue: 0,0:04:06.26,0:04:07.72,Default,,0000,0000,0000,,just to remind ourselves Dialogue: 0,0:04:07.72,0:04:10.31,Default,,0000,0000,0000,,that these two blocks of code\Nare very, very connected. Dialogue: 0,0:04:10.31,0:04:13.80,Default,,0000,0000,0000,,You can't have an {\i1}else{\i0} block\Nunless you've just had an {\i1}if{\i0} block. Dialogue: 0,0:04:13.80,0:04:14.95,Default,,0000,0000,0000,,Got it? Dialogue: 0,0:04:15.41,0:04:18.13,Default,,0000,0000,0000,,This will also help you remember Dialogue: 0,0:04:18.13,0:04:23.14,Default,,0000,0000,0000,,to not put something in between\Nthe two blocks, like {\i1}var y equals zero{\i0}, Dialogue: 0,0:04:23.14,0:04:26.29,Default,,0000,0000,0000,,and that would just break everything!\NSo don't do that. Dialogue: 0,0:04:27.03,0:04:29.90,Default,,0000,0000,0000,,Great. So now we know about if/else\Nwhich is really good Dialogue: 0,0:04:29.90,0:04:32.66,Default,,0000,0000,0000,,when we are deciding\Nbetween two possible things to do. Dialogue: 0,0:04:32.66,0:04:34.46,Default,,0000,0000,0000,,But what if we have more? Dialogue: 0,0:04:34.46,0:04:36.88,Default,,0000,0000,0000,,What if I generated\Nan integer between zero and two Dialogue: 0,0:04:36.88,0:04:40.41,Default,,0000,0000,0000,,and then I had three possibilities:\Nzero, one, or two? What then? Dialogue: 0,0:04:40.41,0:04:42.98,Default,,0000,0000,0000,,Duh duh duh! To be continued!