Troubleshooting
Sooner or later you'll encounter problems with your script; it does not behave as you expect, or even produces error or crash messages.
Under error messages you'll find a list of error messages, and under bugs you'll find some general hints what to do in the case of a crash, plus
a complete list of Gamestudio bugs. However, how can you find bugs in your script?
- Use the SED debugger for single stepping through your code and observing variables.
If you are not using SED, you can use breakpoint comment tags (//!) for makeshift debugging.
If you are not familiar with using a debugger at all, read the lite-C Workshops - two of them deal with debugging.
- If the error occurs randomly, check if it's an uninitialized variable. Use PRAGMA_ZERO and check whether this changes the behavior.
- Set warn_level at its highest value.
This will issue error messages instead of just returning error codes when files are not found or engine functions fail due to wrong parameters.
-
For observing the status of variables or pointers at certain positions in the code, use the draw_text function. For instance, when you place the command draw_text(str_for_num(NULL,result),10,10,vector(0,0,0)); inside a wait() loop, the status of the result variable at that position is permanently displayed in black numbers at the upper left corner of the screen.
- For observing the status of certain entities at runtime: Make sure that default.c is included. Press [Shift-F11]. The game freezes and a cursor appears on the
screen. Click onto the entity you want to observe. The watched pointer will be
set to that entity, causing it's status display to appear on the
screen. Pressing [Shift-F11] a second time will resume gameplay, but
the status display is permanently updated with the status of the last
clicked entity. If you want to get rid of the status display, click
an empty position while in frozen mode.
-
For finding the circumstances under which a certain global variable is changed, place variable comparison expressions at all suspicious places inside your wait loops.
-
If your script terminates unexpectedly and you suspect some hardware problem, start it with the -diag command line option and check the acklog.txt afterwards. If the script behaves erratically and debugging does not help, place diag() or diag_var() calls in your functions. This way you can isolate problematic script lines. This also helps to find the reason of random crashes in your script.
► latest
version online