AI crashing

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

trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

AI crashing

Post by trotter94 »

Hi,
I am trying to create my own ai but i keep getting an error, even with just the minimum code:

Code: Select all

class trAI extends AIController 
{
	
	constructor() {
	}
}

function trAI::Start()
{
	AILog.Info("Starting")
	
  while (true) {
  }
}
error.png
/w code above
(301.37 KiB) Downloaded 2 times
I've tried import the library and also i tried re-installing openttd.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI crashing

Post by Yexo »

That error message does not match your code. Please provide the exact code you're trying to use.
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

It is the exact code (+ info.nut).

It comes up with exact same error message (including same line) whatever code i use.

I've checked that the files are in the right place.

I don't get what Pathfinder.Road has got to do with anything? I wasn't trying to use it at first.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI crashing

Post by Lord Aro »

trotter94 wrote:I don't get what Pathfinder.Road has got to do with anything? I wasn't trying to use it at first.
Hence why it is thought that you didn't post the same code

Where are you putting the code currently?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

Code: Select all

C:UsersThomasDocumentsOpenTTDcontent_downloadaitrAI

Edit: forum doesn't seem to like backslash.
Attachments
trai.png
(1.28 MiB) Downloaded 2 times
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI crashing

Post by Lord Aro »

check in the installation directory of OTTD, it might be hidden somewhere

(see section 4.2 of readme.txt about where things might be located)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI crashing

Post by Zuu »

Put your ai in C:\Users\Thomas\Documents\OpenTTD\aitrAI (don't put your development files in content_download)

You could try to change the short + long name of your AI in info.nut to something that you are sure is unique to make sure that OpenTTD uses your code and not some other AI code.
Last edited by Zuu on 14 Feb 2012 17:52, edited 2 times in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AI crashing

Post by Yexo »

Perhaps your shortname clashes with Trans AI?
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

I haven't downloaded any ai after i re-installed openttd (i have 1 now, ChooChoo.).

I have moved the ai to where zuu said and changed the names, however it still doesn't work and still says trAI in the ai menu (should be long name "TrotterAI" and short name "tAI").
Attachments
info.nut
(502 Bytes) Downloaded 128 times
main.nut
(158 Bytes) Downloaded 144 times
location.png
(333.64 KiB) Downloaded 2 times
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

I found a trAI folder in the program files ai folder, i don't remember putting it there and i re-installed openttd a few days ago.

I deleted that one but TrotterAI doesn't appear in openttd.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI crashing

Post by Zuu »

If it doesn't appear, you probably have a syntax error in your code that is fatal enough that your AI don't show up in the list.

Start OpenTTD with -d to get the start up messages where you'll see which AIs that fail to compile.

Code: Select all

openttd -d
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: AI crashing

Post by MinchinWeb »

I'm pretty sure short names have to be exactly 4 characters long. In your info.nut, try using this line (or something like it) instead:

Code: Select all

  function GetShortName()   { return "tAI_"; }
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

It works if I put it back in the content_download ai folder.

and yes i think it has be 4 letters.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI crashing

Post by Lord Aro »

Zuu wrote:(don't put your development files in content_download)
;)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

Lord Aro wrote:
Zuu wrote:(don't put your development files in content_download)
;)
Well where am i meant to put them!?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AI crashing

Post by Zuu »

In C:\Users\Thomas\Documents\OpenTTD\ai\trAI

(sorry, I forgot to add one slash above in my previous post when fighting against the slash remover in the forum)


or in the "ai" directory of your OpenTTD installation that you use for AI development. (if you want to keep your development AIs way from your other installations of OpenTTD)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

How do you include the standard math library?
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: AI crashing

Post by MinchinWeb »

We don't have a "standard math library"... The most common Libraries are listed on Bananas (here) which hosts the files for the in-game download system. Once you have the library you want, add a line like this near the top of your main.nut:

Code: Select all

import("util.MinchinWeb"' "MinchinWeb"' 4)
The first parameter is the library's category and name, the next is what you want the library's main class to be called in your program, and the third parameter is the version of the library you are importing.
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
trotter94
Engineer
Engineer
Posts: 19
Joined: 06 Feb 2012 23:28

Re: AI crashing

Post by trotter94 »

Does't squirrel have it's own math library?
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: AI crashing

Post by Lord Aro »

Depends what you want

However, you don't need to include anything other than downloaded libraries
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 6 guests