Blade of Darkness holds true to the greatest of hack and slash legends, combining sorcery, knights, and swords with god forsaken enemies that deserve to have their arms slashed off with a broadsward. Blade of Darkness looked excellent in 2001, and still delivers its gore well today. Holding True to it's genre it offers modders both custom maps and scripts. Relevent Links Fansite Mod List Modding Community

Post tutorial Report 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.

Console

How to enable the console is covered in Josh's Blade Mods site Dahlby.net 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/ConsoleOutput.py. There is a var DEBUG_FILE. It will be set to 0. Change the 0 to 1.

DEBUG_FILE = 1

---------------------------------------------------------------------
WHOOPS!

I have just realised that there is more to the ConsoleOutput.py.

This is the complete code for the file:

python code:
import Console
import sys

DEBUG_FILE=1

class ConsoleOutput:
    softspace=0

    def write(self,message):
        if message is None:
            Console.ConsoleOutput("None")
        else:
            if DEBUG_FILE:
                dbg=open("Debug.txt","at")
                dbg.write (message)
                dbg.close()
            Console.ConsoleOutput("None")
       
    def flush(self):
        pass


def InitConsole():
    ConsoleOut=ConsoleOutput()
    sys.stderr=sys.stdout=ConsoleOut


--------------------------------------------------------------------

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 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 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.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: