![]() ![]() Select if to add a condition to the statement. Select the statement self.speed -= 5 in the brake method and then press Control+Alt+T ( Code | Surround with): To avoid running into the same problem again, let's update the brake of Car so that it doesn't decrease speed to negative values. So the reason for an unexpected result is the negative value of the speed variable. You can click on the toolbar to make sure that it happens. ![]() That's why when we resume the execution, odometer will become 0. You can see, that the value of odometer is 5, and the value of speed is -5. Now, let's switch to the Threads & Variables tab and analyze what's going to happen next: Note that speed is 0 at the moment.Ĭlick and brake again ( b + Enter). Go back to the Threads & Variables tab and examine the variables. Instruct the car to brake by pressing b followed by Enter. Now click ( Resume) and switch to the Console tab in the Debug tool window. Note that the value of odometer becomes 5, and line 16 is now highlighted in the editor, as it's going to be executed next: Expand self to examine the current values of the variables:Ĭlick ( Step Over) on the debugger toolbar, to execute the line with the breakpoint. The Threads & Variables tab of the Debug tool window will open. The debugger will execute the script and stop at the breakpoint. Press a followed by Enter to accelerate the car. P圜harm starts a debugging session and shows the Debug tool window. Next, click the icon in the gutter, next to the main clause, and choose Debug 'car'. ![]() The car's odometer is set on line 15, so let's put a breakpoint there. The debugger will stop just before executing the line with the breakpoint, and you will be able to examine the current state of the program. To start debugging, you have to set a breakpoint first. Let's debug the code to find out the reason for that. The script is telling us that the car has travelled 0 kilometers! It's an unexpected result, because we've pushed the accelerator once, so the car should have covered some distance. Now press o followed by Enter to show the car's odometer: Run the script, accelerate the car once, and then brake it twice by typing the corresponding commands in the Run tool window: ![]() Remember, in the previous tutorial you've created and run the Car script? Let’s play a little more with it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |