A case for better debugging tools - ATTDebug

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

A case for better debugging tools - ATTDebug

Post by Attila7 »

A lot of people are writing AI and GS scripts with little to nothing in tools to help debug some rather complicated programs.

I felt like this already way back in 2010 when I developed an interactive debugger that I used heavily back then. The problem was that it requires a fair number of modifications to OTTD to make the built-in Squirrel debugger work. The original thread can be seen here: viewtopic.php?f=65&t=51612

I want to try and reintegrate that code with the current version of OTTD, but a lot has changed since 2010. In particular, the debug window code has seen a major rewrite. For the debugger to work, it needs to be able to get input from the user and as you can see on the screenshot in the above link, I used an input line at the bottom of the debug window. I also added a function - AIController.GetDebugInput - that could be called from a script to get the input.

What I need is someone to give me an idea how to go about adding an input line to the debug window and how to add the GetDebugInput function so it will work in AI and GS scripts. I think I can do the rest, but if someone more familiar with the code could do this part, it would save me a lot of time. (I need actual code - not where to look :)

I also think that the capability to provide input to a running script should be a standard feature in trunk, as it would allow for the examination of variables at run-time, without having to put Log statements everywhere.

The last time RL interrupted my involvement with OTTD, but now I should be able to devote more time to it. If I can get the debugger working, I will make it available to the community.

If you are interested in seeing how this worked on r21365, I have included two zip files from Windows 7:
- OpenTTD.zip should replace your OpenTTD folder in Documents. Make a copy of your current one first.
- OpenTTD - old.zip contains the modified openttd.exe that can run the debugger and all the files needed to run the game, my ai (YATT) and ATTDebug.
To see some examples of a debug session, see some of the ATTDebug log files in this folder.

Everything should be set up for you, just run the game and create a new game, will be in Pause mode...
Open the AI debug window - should be blank...
Unpause the game and accelerate time until the AI starts - it will stop at line 104 in cATT\Main and ATTDebug will be in control
At this point you can enter ATTDebug commands in the input line. Enter the following commands in order:
show calls // Displays the call stack
type 100:110 // Lists the source code line 100 to 110
examine s_cfg // Displays contents of table s_cfg
step/into // Executes the instruction on line 104 and steps into the first function called
sh c // Can abbreviate commands
s // Step
ex engid

You get the idea :)

To see the ATTDebug documentation, download the ATTDebug_1_0.zip file from the page linked above.
Attachments
OpenTTD-old.zip
(18.43 MiB) Downloaded 75 times
OpenTTD.zip
(5.3 MiB) Downloaded 78 times
Attila
"Artificial intelligence is no match for natural stupidity."
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: A case for better debugging tools - ATTDebug

Post by HGus »

One way to in interacts with running AIs and GSs is via signs.

There is a GS library that can comunicate with AIs using signs. The Goals GS uses it.

You can create your own library that can read signs from the map, filter special command chars (just like the script for the Split Scenario does), parse the commands and execute them inside your GS. As far as the sintax is correct, you can use the Squirrel compile() function, otherwise you should write an specialized control function.

I already used this system for sending logic commands to a test AI.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests