Debugging with Visual Studio

This page is meant only for advanced scripting: you will not need this if you only set up scripts using the instructions on the previous pages.

If you have Visual Studio, you can step through your script code as it is running in the game. I have only tried this with the free Express Edition of Visual Studio, and with this version, you can only step through your code, and not see variables or change them.

The steps to set this up (using the Express Edition) are as follows:

  1. Install the Visual C++ Express edition, available from Microsoft. We need the C++ edition because that's the only Express version that has an "attach to process" option. You do not need the extra Platform SDK mentioned in step 4 on that page.

  2. Configure Caesar IV such that it runs in Windowed mode. To do that, open the file "CaesarIV.ini" in a text editor (Notepad will do), and change the line "Full Screen Mode 1" to "Full Screen Mode 0". You might need to change the in-game resolution to a value lower than your desktop resolution for this to work.

  3. Open Visual C++.

  4. Start Caesar IV in windowed mode. Leave it at the main menu and switch to Visual C++.

  5. From Visual C++, go to Tools -> Attach to Process. Select Caesar IV from the list and click "Attach"

  6. Now open the script file you want to debug: still in Visual C++, just open the file. It will display it as a rather plain file without any syntax highlighting.

  7. Set breakpoints on the script where you want the debugger to break: click in the grey left margin to add a breakpoint. A red circle with a warning sign will appear there, with a note that the breakpoint will not be hit because "no symbols have been loaded for this document". This warning can be ignored.

  8. Go back to Caesar IV and load the scenario/saved game you want to debug.

  9. When a breakpoint in the script is hit, you'll be switched back to Visual C++. The sad thing is that you will not be able to see variables and their values. You will, however, be able to step through the code with F11, F10 and shift+F11 (step into, step over, and step out, respectively).

If you have the full version of Visual Studio, I assume the process is much the same, but perhaps there you will be able to see variables.

< Previous: scripting: game constants | Editor Home