How to make Ai?

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
openttdfan2020
Engineer
Engineer
Posts: 19
Joined: 31 May 2019 21:26

How to make Ai?

Post by openttdfan2020 »

I really like those ais.
But i wanna make the ai just like them.
IDK how to make those, Can you help me guys?
:D
User avatar
jfs
Tycoon
Tycoon
Posts: 1758
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: How to make Ai?

Post by jfs »

Long story short:
1. Learn the Squirrel programming language
2. Learn the OpenTTD AI API
3. Look at existing AIs and available AI libraries for examples and bases to start from
4. Write some code
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: How to make Ai?

Post by Yexo »

The wiki has a few interesting pages for you:. Start with https://wiki.openttd.org/NoAI and https://wiki.openttd.org/AI:Introduction.
RockyPapery
Engineer
Engineer
Posts: 16
Joined: 08 Apr 2020 13:23

Re: How to make Ai?

Post by RockyPapery »

I would love to make one too. The problem is there is no one explaining how to install the squirrel. I do code but for some reason installing squirrel language is like walking in a labyrinth and there is no instruction anywhere. The only thing I found is how to install SQuirrel DataBase, bummer.
User avatar
jfs
Tycoon
Tycoon
Posts: 1758
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: How to make Ai?

Post by jfs »

You don't need to install Squirrel, everything required to run the AI is already built into OpenTTD. All you need is a text editor to write the code, and place the files in the right location.
RockyPapery
Engineer
Engineer
Posts: 16
Joined: 08 Apr 2020 13:23

Re: How to make Ai?

Post by RockyPapery »

Ooh that's great. So how do I debug then, you know, to check some spelling error, missing semicolon, etc?
And how do I type Squirrel language without autocomplete and libraries? I do code in C++ though
User avatar
jfs
Tycoon
Tycoon
Posts: 1758
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: How to make Ai?

Post by jfs »

I believe there is Squirrel syntax highlighting available for most major text editors, e.g. VS Code and Notepad++ should have it. I don't know about any autocompletion tools.
You can run OpenTTD with debug logging enabled to get syntax errors printed when it tries to load a script.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: pwhk and 24 guests