Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sun May 19, 2019 9:27 pm

All times are UTC

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Sep 29, 2017 1:50 pm 

Joined: Mon May 31, 2010 9:06 pm
Posts: 37
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:

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:
- should replace your OpenTTD folder in Documents. Make a copy of your current one first.
- OpenTTD - 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 file from the page linked above.

Attachments: [18.43 MiB]
Downloaded 24 times [5.3 MiB]
Downloaded 26 times

"Artificial intelligence is no match for natural stupidity."
PostPosted: Mon Nov 06, 2017 2:00 pm 

Joined: Sun May 12, 2013 10:28 pm
Posts: 94
Location: Argentina
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.

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.