WEBVTT 1 00:00:01.227 --> 00:00:04.111 In this demo I'm going to show you how to make an object 2 00:00:04.112 --> 00:00:07.113 perform it's actions by calling it's methods. 3 00:00:07.229 --> 00:00:11.220 I have a bicycle object, created as we saw in the last demo 4 00:00:11.224 --> 00:00:15.221 and I'm going to inspect that object so that we know 5 00:00:16.000 --> 00:00:18.119 what the properties of the object are to begin with, 6 00:00:18.220 --> 00:00:22.118 so we have pedalRpm zero, gear one 7 00:00:22.221 --> 00:00:26.225 wheelDiameter zero point five and five gears 8 00:00:28.220 --> 00:00:30.221 to see what actions an object can do 9 00:00:30.222 --> 00:00:34.001 we can right click on the object in the object bench 10 00:00:34.114 --> 00:00:37.005 and this shows us a menu with a list of the methods 11 00:00:37.006 --> 00:00:40.002 that are available for this object. 12 00:00:41.115 --> 00:00:44.114 The first thing I want to do is to start pedalling the bicycle 13 00:00:44.116 --> 00:00:47.111 to make it move or at least to model this happening 14 00:00:47.226 --> 00:00:51.007 I can call the method setPedalRpm to do this 15 00:00:51.114 --> 00:00:54.008 so I click on that option in the menu 16 00:00:54.119 --> 00:00:57.221 and I see a dialog box the method call dialog box 17 00:00:57.222 --> 00:01:00.004 and thats asking me for some information 18 00:01:00.113 --> 00:01:03.115 about how to do this, what pedalRpm value 19 00:01:03.117 --> 00:01:06.112 would I like to set, this is a 20 00:01:06.112 --> 00:01:08.227 parameter of the method is some information that the 21 00:01:08.228 --> 00:01:11.225 method needs in order to do the action 22 00:01:11.229 --> 00:01:14.112 or for the object to do the action 23 00:01:15.005 --> 00:01:18.004 we'll give that a value of three hundred. 24 00:01:19.226 --> 00:01:22.111 I can now inspect the object 25 00:01:22.117 --> 00:01:24.226 and you can see that the pedalRpm 27 00:01:25.003 --> 00:01:28.225 property has changed value to three hundred 28 00:01:30.118 --> 00:01:33.007 so I wonder how fast the bicycle is going now 29 00:01:33.225 --> 00:01:35.228 well I can ask the bicycle to tell me 30 00:01:36.111 --> 00:01:38.228 if I look at those methods again, it has a method called 31 00:01:38.229 --> 00:01:42.006 speed and that's going to calculate how fast bicycle is going 32 00:01:42.009 --> 00:01:45.001 and it's going to tell me the result of that 33 00:01:45.226 --> 00:01:48.226 this method unlike the setPedalRpm one 34 00:01:48.227 --> 00:01:50.117 doesn't need any information 35 00:01:50.223 --> 00:01:52.220 in order to perform the action. 36 00:01:53.000 --> 00:01:55.229 What it does instead is it returns a result 37 00:01:56.001 --> 00:01:59.113 it gives me back an answer so lets click on that 38 00:01:59.225 --> 00:02:02.113 that pops up a different type of dialog box this is a 39 00:02:02.114 --> 00:02:04.118 method result dialog box 40 00:02:04.226 --> 00:02:07.114 and that gives me the result of calling the method 41 00:02:07.116 --> 00:02:12.005 and it tells me that the speed is seven point eight five. 42 00:02:14.115 --> 00:02:16.006 The speed of a bicycle depends on 43 00:02:16.007 --> 00:02:18.000 how fast it's being pedalled 44 00:02:18.009 --> 00:02:20.005 and also on what gear is selected 45 00:02:20.006 --> 00:02:21.119 so the bicycle object 46 00:02:21.224 --> 00:02:23.225 is another method that lets us 47 00:02:23.228 --> 00:02:25.220 change the gear 48 00:02:26.117 --> 00:02:28.227 I'm going to call the change gear method 49 00:02:29.008 --> 00:02:31.221 and up pops a method call dialog 50 00:02:32.005 --> 00:02:33.222 changeGear is a little bit different 51 00:02:33.223 --> 00:02:35.118 from setting the pedalRpm 52 00:02:35.229 --> 00:02:37.110 on most bicycles 53 00:02:37.119 --> 00:02:40.220 you change gears sequentially, to get from gear one 54 00:02:40.223 --> 00:02:42.220 to gear three you have to go through 55 00:02:42.223 --> 00:02:44.220 gear two and so on 56 00:02:44.227 --> 00:02:46.224 so we really only have two choices here 57 00:02:46.225 --> 00:02:48.009 for changing gear do we change 58 00:02:48.112 --> 00:02:50.119 up or do we change down. 59 00:02:51.004 --> 00:02:52.222 there's some commentary here in the 60 00:02:52.223 --> 00:02:55.004 dialog box that tells us that 61 00:02:55.112 --> 00:02:57.110 if we put in a value zero here 62 00:02:57.111 --> 00:02:59.112 that means we're changing down 63 00:02:59.118 --> 00:03:02.009 if we put in a value one, we're changing up 64 00:03:02.112 --> 00:03:04.227 so lets try a value of one, 65 00:03:06.220 --> 00:03:10.115 and lets inspect the object to see whats happened 66 00:03:11.004 --> 00:03:12.220 and we can see that the gear 67 00:03:12.221 --> 00:03:15.221 value has changed from one to two. 68 00:03:18.118 --> 00:03:20.000 Changing gear should have an 69 00:03:20.000 --> 00:03:21.114 effect on the speed of the bicycle 70 00:03:21.118 --> 00:03:23.227 so lets call the speed method again 71 00:03:24.116 --> 00:03:26.009 and we get a different result showing that 72 00:03:26.110 --> 00:03:29.115 the bicycle has speeded up because we changed gear. 73 00:03:33.007 --> 00:03:35.007 What happens if we keep changing gear 74 00:03:35.116 --> 00:03:38.115 well lets call changeGear again 75 00:03:39.002 --> 00:03:42.000 and again enter one so we change up 76 00:03:42.005 --> 00:03:43.119 and inspect 77 00:03:44.002 --> 00:03:46.110 and we're now in gear three 78 00:03:46.222 --> 00:03:49.005 lets do that again 79 00:03:49.227 --> 00:03:52.110 again changing up 80 00:03:54.007 --> 00:03:57.004 inspect again and we are in gear four 81 00:03:58.224 --> 00:04:04.222 and one more time change gear up again 82 00:04:05.116 --> 00:04:09.009 and inspect again gear five 83 00:04:10.223 --> 00:04:13.115 and one more time, lets keep trying to change up 84 00:04:13.119 --> 00:04:16.113 change gear up 85 00:04:17.221 --> 00:04:21.115 and inspect again, and we're still in gear five 86 00:04:22.008 --> 00:04:24.117 so that last time we called changeGear 87 00:04:24.118 --> 00:04:26.114 and request it to change up 88 00:04:26.118 --> 00:04:28.221 it didn't actually change and thats because 89 00:04:28.226 --> 00:04:30.005 this bicycle only 90 00:04:30.008 --> 00:04:32.112 has five gears so it doesn't make sense 91 00:04:32.115 --> 00:04:33.221 to be able to change 92 00:04:33.229 --> 00:04:36.229 to a gear any higher than gear five. 93 00:04:38.001 --> 00:04:41.113 If I changeGear again and change down 94 00:04:41.222 --> 00:04:43.227 however that should be possible 95 00:04:44.117 --> 00:04:46.116 so lets see if thats happened 96 00:04:46.117 --> 00:04:50.005 inspect and yes the gear has gone back down to four. 97 00:04:50.118 --> 00:04:51.221 What do you think would happen 98 00:04:51.224 --> 00:04:55.003 if I kept changing gear down repeatedly?