API

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
User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

API

Post by Bennievv » 11 Feb 2012 12:20

Does OpenTTD got an API?

Bennievv Newbie

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: API

Post by Yexo » 11 Feb 2012 12:23

For what? Just read some basic in this forum or on the wiki. We have an API to write AIs and one to write GameScripts. I guess you could call the NewGRF specifications an API too.

Edit: and let's not forget the admin port.

User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

Re: API

Post by Bennievv » 15 Feb 2012 18:00

For AI's :wink:

User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

Re: API

Post by Bennievv » 15 Feb 2012 18:04

I found it:
http://wiki.openttd.org/Noai

EDIT Oops, I did say "API", but I needed a turtorial. :(
Last edited by Bennievv on 15 Feb 2012 18:47, edited 1 time in total.

User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

Error

Post by Bennievv » 15 Feb 2012 18:34

Uh... I have made a folder at OpenTTD/AI named "MyNewAI", with the info.nut file:

Code: Select all

class MyNewAI extends AIInfo {
  function GetAuthor()      { return "Bennievv"; }
  function GetName()        { return "MyNewAI"; }
  function GetDescription() { return "An example AI by following the tutorial at http://wiki.openttd.org/"; }
  function GetVersion()     { return 1; }
  function GetDate()        { return "2012-02-15"; }
  function CreateInstance() { return "MyNewAI"; }
  function GetShortName()   { return "XXXX"; }
  function GetAPIVersion()  { return "1.0"; }
}

RegisterAI(MyNewAI());
...and main.nut file:

Code: Select all

class MyNewAI extends AIController 
{
  function Start();
}

function MyNewAI::Start()
{
  while (true) {
    AILog.Info("I am a very new AI with a ticker called MyNewAI and I am at tick " + this.GetTick());
    this.Sleep(50);
  }
}
...but if I type

Code: Select all

start_ai MyNewAI
...I get the error:

Code: Select all

WARNING: Failed to load the specified AI

User avatar
FooBar
Tycoon
Tycoon
Posts: 6559
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: API

Post by FooBar » 16 Feb 2012 12:13

Do you have the AI files stored in the correct directory, so that OpenTTD can find them?
In other words: does you AI show up in the ingame (GUI) list?

User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

Re: API

Post by Bennievv » 16 Feb 2012 13:01

I maded it in OpenTTD/ai/MyNewAI, and I don't see it in the GUI-list...
But I gonna check it again...

User avatar
Bennievv
Engineer
Engineer
Posts: 12
Joined: 11 Feb 2012 12:14
Location: The Netherlands

Re: API

Post by Bennievv » 16 Feb 2012 13:16

Now it works!

rplus
Engineer
Engineer
Posts: 3
Joined: 19 Aug 2013 13:08
Location: Wrocław, Poland

Re: API

Post by rplus » 28 Jan 2019 21:39

Hi,

I've got the same issue.

Tried in C:\Program Files\OpenTTD\ai\MyNewAI\ and C:\Users\<user_name>\Documents\OpenTTD\ai\MyNewAI\ on Windows 10.

My AI does not show up in list_ai results.

Any hints?

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9278
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: API

Post by planetmaker » 29 Jan 2019 01:01

My best bet is "some of the necessary info is missing". Hard to tell.

Call OpenTTD in debug mode to check:

You can test the detected AI and libraries by calling "openttd --help" in the command line. And possibly by calling it in debug mode: "openttd -d script=X" where X is a number 1...9. The higher the more spammy it will get.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests