Skip to content

Python debugging

johan-buret edited this page Oct 25, 2023 · 6 revisions

Tools to download

Python 2.4.1

available at https://www.python.org/downloads/release/python-241/

It is the exact version Civ4Col uses.
Better install it on a short folder e.g C:\Python24\.
It is not needed to put it in the PATH .

HAP debugger

available at this link : https://sourceforge.net/projects/hapdebugger/files/HapDebugger%20Binaries/Hap%20Debugger%205.1/HapDebugger_Aug_27_2005.zip/download\ That one works on my Windows 10 computer.
The 2013 compiled one doesn't. Don't know why.

JetBrains community edition 2016.1

Available at https://www.jetbrains.com/pycharm/download/other.html
Take the Community Edition

Important

It is the last version of this IDE to support Python 2.4


Setting up HAP debugger

Check the Tools > Options menu
image

Warning

Don't use the Break on all exceptions choice, as the main game engine abuses Python exceptions on startup, to retrieve all needed modules. Doing so will prevent the Colonization main menu window to show up.

Suggested setup : image


How to enable Python debugging within Civ

In the CivilizationIV.ini of your personal folder. Reeplace these options:

; Move along
CheatCode = chipotle

<let the other entries at their values>

; Establish connection to Python Debugger
HAPDebugger = 1

The next time you launch Colonization, it will hang at the Init Python step, waiting for the debugger to connect.

Launch HAPDebugger.exe

image

Then
image

You can also open a script file, and set a breakpoint at the place you need them.
HAP will honor it, stop at the indicated place, but not underline the line in red, like a full IDE would. 😢