Debugging your game

From Spheriki

Jump to: navigation, search

There are many ways to test your game. In a structured way, you can develop your code using test_first] but for small games this is overkill.


Contents

Simple Debugging example: OpenLog

Open your game.js and put this as the first line:

DEBUG = OpenLog('DEBUG'); //temporal while Debugging.

Each time you run your game, it will start logging in your ../log/ directory!

To see text being added to your logfile in realtime use "tail -f" in unix or baretail in windows

Now, lets say you want to test why the map changes dont fade in/out while you used SetColorMask to fade in and out.

Lets change the SetColorMask function, so it logs when you use it:

// Store the real function into this other one:
REAL_SetColorMask = SetColorMask;
// Now redefine the function:
SetColorMask = function(color, num_frames, mymessage){
  // Log a good message filled with all the information you need:
  DEBUG.write( "(" + color.red + "," + color.green + "," + color.blue + "," + color.alpha +")," + num_frames + "[" + arguments.caller +"]:"+ mymessage);
  // And now call the REAL function to do its work:
  REAL_SetColorMask(color, num_frames);
}

Note that the real function only takes 2 parameters, and we allow for a third one to log a message. Dont forget to remove this extra parameter when done debugging. Although many functions dont mind, some can.

Now you can do this:

SetColorMask(CreateColor(0, 0, 0, 255), fadeOutFrames, 'FadeToblackOUT');

Advanced Debugging: Sphere Javascript Unit Test Module

What is Unit Testing?

<todo>

download

unittest.js is based on the following two software:

  • jstest: Simple JavaScript testing library, v1

Copyright Kragen Sitaker, 2005. Licensed under GNU GPL.

  • JSUnit.net

Licensed under GNU GPL 2, 2.1 and Mozilla Public License 1.1

There are two systems available for Sphere:

Very Basic UnitTest class for Sphere projects Sphere Javascript Unit Test Module

Personal tools