SEVERANCE, BLADE OF DARKNESS

Prospero's pages

Updated July 24, 2005

HOME PAGEAUTHORS > PROSPERO > BOD PYTHON SCRIPTING (12)

 

Tut12. De-bugging.

When you start coding, you get bugs. Python is very unforgiving and little things can cause errors. A , missed will cripple the whole process. When the map loads, Python will read all the files in the order they were executed. If it finds an error it stops there. The map will continue to load, but all the code past the error will not be exec'd. This in itself gives you a clue to the error: if you get all your objects but enemies are missing then you can deduce that the objects file is OK but the error is in the enemies file.

Console.

How to enable the console is covered in Josh's Blade Mods site
http://www.dahlby.net/games/blade/ . I'll just add a little note on the filepath. After the exe at the end TYPE A SPACE before adding -console. The space is critical.

With the console enabled you get a readout of everything that is going on in the course of a map. To get more use print statement in your code:

print "The function was executed"

This will appear in the console. If you put this at the end of a block of code, you know that the code is sound. If it doesn't appear when it should, you know that the error is before the print statement.
If you do this:


def Func1():
    print "Starting to exe func1"
    *lots of strange code here*
    print "func1 done"


If you get the first statement but not the second, you know that the error is somewhere inbetween. The console will sometimes tell you what is wrong and give the file and line number of the offending code.
Sometimes this is helpful, sometimes slightly cryptic. If you get a complete crash to the desktop, you loose the console and can't see what happened last that might have caused the crash. There is a neat method whereby the console output can be saved to a
.txt file.
Open up the file
Lib/ConsoleOutput.py. There is a var DEBUG_FILE. It will be set to 0. Change the 0 to 1.

DEBUG_FILE = 1

At the same time enable the Debug mode in
Lib/Reference.py. There are two vars DEBUG_INFO and PYTHON_DEBUG (lines 24/25). Set DEBUG_INFO = 1 and PYTHON_DEBUG = 2.

This will give you lots of messages in the console and also enable certain development aids. (Or 'cheats' as some incharitable people call them.) The T key will cycle though various onscreen readouts.
The first is the most useful. It gives Framerate, current Player Position and Mission Time. While in this mode The K (kill),P (freecamera) and F10 (godmode) keys are enabled. Other keys are now active but are not quite so useful. If you play main RAS maps in this mode be careful not to hit the Numpad keys. They will teleport you about. Later, when your map has grown to enormous size, you can make a
Positions.py file to take advantage of this feature. It saves having to fight your way all though the map just to test a bit near the end.