Image:
 Author: Xray Group: Default Filesize: 61.14 kB Date added: 2012-11-13 Rating: 5.5 Downloads: 738 Views: 587 Comments: 3 Ratings: 2 Times favored: 0 Made with: Algodoo v2.0.2 Tags:
|
Some of my Thyme scripts get rather large and complex, and the larger and more complex any piece of software becomes, then the more difficult it becomes to modify it and to debug it. I want to share a tool that I use which helps me a great deal during the debugging process. It is called a BREAKPOINT. Back in my early days of programming, I wrote and maintained programs for 8-bit embedded systems. We used a hardware tool called an emulator which allowed the software engineer to step through his/her code, one instruction at a time. Also, you could set breakpoints, which are specific addresses at which you want the emulator to halt, so you could check certain variables and I/O ports. The use of breakpoints was essential for debugging software. Well, I thought that it would be great if I were able to set breakpoints in my Thyme scripts. Since I do not have a hardware emulator, I must implement software breakpoints. A software breakpoint is a small piece of code that you place anywhere in your script where you want to determine the value of a variable either before or after it was written to. A breakpoint not only saves the condition of the variable at that point in the program, but it also HALTS the simulation so that the variable cannot be changed again until you've observed what you need to see.
A common breakpoint that I use is only two lines of script. The first line reads the desired variable and places the value in the text variable of a box so that I could immediately see what the value is. The second line of script is what stops the simulation, which is SIM.RUNNING = FALSE. In some scripts I may have two or three breakpoints in different areas that monitor specific variables at specific times. Breakpoints can also be conditional by using If/then statements. For example (here I use pseudo-code for explanation), Xvar == 5 ? {print Yvar; stop sim}:{ignore}. After your breakpoint is no longer needed, simply delete it, or cut and paste it at some other script line where you need to know some other values.
In this scene, I also demonstrate how certain scripts in Algodoo continue to execute even while the simulation has stopped. Script that are triggered by collision or laser, will stop immediately when the simulation stops, but script written in certain variables, such as "airFrictionMult", will continue executing regardless of the status of the simulation.
Play with this scene until you understand it, and then go play around with your own script! |