{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreicauia7c7b36ifwhtobky2qgsjo5zo5qn7j3lz3de3ivtmt3bghi4",
"uri": "at://did:plc:i7budt2wflrcfy6jtvfocbix/app.bsky.feed.post/3mhc44tcwbfx2"
},
"path": "/viewtopic.php?p=1278592#p1278592",
"publishedAt": "2026-03-17T19:50:50.000Z",
"site": "https://www.tt-forums.net",
"tags": [
"https://github.com/samisalreadytaken/sqdbg-vs",
"https://github.com/PaSaSaP/OpenTTD-sqdb ... penttd.exe",
"https://github.com/PaSaSaP/OpenTTD-sqdbg-debugger",
"openttd-sqdbg.gif",
"MustBe"
],
"textContent": "For quite a long time, debugging AI / GameScripts in OpenTTD has mostly meant printing values and reading logs:\n\nCode:\n\n\n AILog.Info(\"value = \" + value);\n\nor similar approaches.\n\nI experimented with integrating the Squirrel debugger (sqdbg) into OpenTTD, and it turns out it is possible to attach a real debugger to running AI / GameScript instances.\n\nCurrent state\n\nThe prototype currently supports:\n\n * attaching an external debugger\n * breakpoints\n * stepping\n * inspecting variables\n * works with both AI and GameScripts\n\nTested with VS Code using the sqdbg extension: https://github.com/samisalreadytaken/sqdbg-vs\n\nHow it works\n\nEach Squirrel VM exposes a debug port.\n\nPorts are assigned sequentially starting from:\n\nCode:\n\n\n 2222\n\nSo typically:\n\nCode:\n\n\n GS -> 2222AI0 -> 2223AI1 -> 2224AI2 -> 2225...\n\nPorts are printed to the console, so OpenTTD needs to be started with:\n\nCode:\n\n\n -d\n\nThen you can attach the debugger to the port corresponding to the AI / GS instance.\n\nExample workflow\n\n * start OpenTTD with -d\n * load a game with AI or GameScript\n * check console output for assigned port\n * attach debugger (e.g. from VS Code)\n * set breakpoint\n * execution stops at that point\n\nFunction breakpoints\n\nFunction name matching is currently limited.\n\nThere is no support for:\n\nCode:\n\n\n Class.MethodClass::Method\n\nOnly the function name itself is used:\n\nCode:\n\n\n Method\n\nThis means that if multiple classes define functions with the same name, function breakpoints may trigger in multiple places.\n\nIn such cases, regular line breakpoints are more reliable.\n\nDownloads\nWindows x64 binary: https://github.com/PaSaSaP/OpenTTD-sqdb ... penttd.exe\n\nSource code: https://github.com/PaSaSaP/OpenTTD-sqdbg-debugger\n\nVS Code setup (sqdbg)\n\nExample launch.json configuration:\n\nCode:\n\n\n { \"version\": \"0.2.0\", \"configurations\": [ { \"type\": \"squirrel\", \"request\": \"attach\", \"name\": \"Attach to OpenTTD\", \"port\": 2222 } ]}\n\nHow to use\n\n\n * Install the sqdbg VS Code extension: https://github.com/samisalreadytaken/sqdbg-vs\n * Create or edit .vscode/launch.json in your project.\n * Set the port to match the one printed by OpenTTD (requires running with -d).\n * Start OpenTTD, load a game with AI / GameScript.\n * In VS Code:\n * select \"Attach to OpenTTD\"\n * press Start Debugging (F5)\n * Set breakpoints in .nut files and run the script.\n\nExecution will pause when a breakpoint is hit.\n\nDemo\n\n\n\nopenttd-sqdbg.gif\n\nNotes\n\n * based on OpenTTD 15.2\n * currently implemented as a patched build\n * each VM uses a separate port (no multiplexing)\n\n\n\nStatistics: Posted by MustBe — 17 Mar 2026 19:50\n\n* * *",
"title": "OpenTTD Development • Squirrel debugger support for OpenTTD (AI / GameScript) – prototype",
"updatedAt": "2026-03-17T19:50:50.000Z"
}