The Game Scripting Plugin includes a Windows form which gives you real-time information about the state of your script. This is useful for the following reasons:
- Due to their delayed execution Scripts are harder to debug compared to regular code.
- Scripting is intended to be easy enough for non-technical users. These users may not be familiar with Visual Studio’s debugger.
- Real-time information can be useful even for individuals who are comfortable debugging complex code in Visual Studio – the real-time view can often solve simpler bugs faster than debugging with Visual Studio.
The debugging built in to the scripting plugin can only be used on Windows. Of course, you can still use regular Visual Studio debugging on other platforms.
Preparing for Integration
To integrate the debugging form, you must already have:
- A Glue project
- Added the Game Scripting Plugin core classes
- Created a class which inherits from ScriptEngine
- Added an instance of the ScriptEngine-inheriting class into your game
If you are unsure about how to do any of the above steps, you should review the
game scripting implementation tutorial.
For the rest of this tutorial we will use a Screen called GameScreen – this is the name of the Screen that was used in the game scripting implementation tutorial.
Adding necessary references
You need to add references to your project which are used by the debugging code. To do this:
- Expand your project in Visual Studio
- Right-click on the References item
- Select Add Reference…
- Select the Assemblies -> Framework category
- Check the following items:
- Select System.Data
Adding Debug Controls to Your Project
Next we’ll add debug controls to our project.
- Open or focus Glue
- Select Plugins -> Add Game Script Debugging Classes
The Debug control is only available on Windows platforms (because it uses Windows Forms), so the code is surrounded by a WINDOWS pre-compile directive.
To access this, you will need to add WINDOWS to your project’s conditional compilation symbols:
- Right-click on your project
- Select Properties
- Click the Build category
- Add WINDOWS to the Conditional compilation symbols text box (all values should be separated by a semicolon)
Creating the Debug Form
To add a debug form, open GameScreen.cs (or the custom code file that contains your ScriptEngine-inheriting class.
Add the following at class scope:
Add the following in your Screen’s CustomInitialize after you initialize your script
// Assuming mScripts is the name of your script instance mScriptDebuggingForm = new ScriptDebuggingForm(); mScriptDebuggingForm.ShowWithScripts(mScript);
Add the following to your Screen’s CustomActivity
Note: You will need to add the following using statement to qualify the ScriptDebuggingForm:
If you run the game you will now see the debug window list the events you have in your game.
The Script window already shows us some useful information. We can see that we have 3 scripts which have conditions “HasPlayerPassed”. This name comes from the “HasPlayerPassed” function which is called in our If’s in the game script. The debugging form automatically detects this as the name based off of the method that created the delegate.
Also, the debugging window tells us how many actions exist in the script in parentheses. Each script has one action, so each says (1) after the If call.
The scripts will default as written in black. When they execute, they will change to green, so you will be able to see how scripts execute in real-time.
Finally, you can expand the scripts to see the names of the actions that will execute.