Post tutorial RSS Level Editing Scripting by Prospero. Part. 11

When you start coding, you get bugs. Python is very unforgiving and little things can cause errors.

Posted by on - Basic Client Side Coding

Tut 11. 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 executed. 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.


How to enable the console is covered in Josh's Blade Mods site 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:

python 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:

python code:
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/ There is a var DEBUG_FILE. It will be set to 0. Change the 0 to 1.



I have just realised that there is more to the

This is the complete code for the file:

python code:
import Console
import sys


class ConsoleOutput:

    def write(self,message):
        if message is None:
            if DEBUG_FILE:
                dbg.write (message)
    def flush(self):

def InitConsole():


At the same time enable the Debug mode in Lib/ There are two vars DEBUG_INFO and PYTHON_DEBUG (lines 24/25). Set DEBUG_INFO to 1 and PYTHON_DEBUG to 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 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.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.