Script Communication Protocol

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
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Script Communication Protocol

Post by krinn »

Zuu and I made the Script Communication Protocol (SCP), and before you asked what is SCP ?
SCP is 3 things:
  • a protocol to allow scripts to communicate with each other
  • an implementation library for Goal Script
  • an implementation library for AI script
So an AI, using the SCP library for AIs, can communicate with a GS that use the SCP library for GS. AI->AI communication is planed, but has not been finished and will be restricted by AI and GS settings.
With SCP, an AI can ask a GS for its settings, goals... anything the GS wish to provide to the AI, allowing the AI to really handle the GS in use.
What the AI or GS can ask/answer is all up to the AI/GS authors, we provide the interface to speak, but you must create your own API (through commands and command sets; see the wiki page) so others devs could use it.

You can grab : Current (not yet finished) documentation can be found here : http://wiki.openttd.org/Script_communication_protocol

As these libs are used by devs and not by users, I'm sure even without doc, many would love to try it and start implementing it in their own scripts. Since this is work in progress, we don't yet publish the libs in bananas yet, but you can get them here. We still need to document the source code and build the API documentation and the implementation documentation.

The libraries are licensed under GNU/Affero, any AI/GS incompatible with it (non GNU/GPL), can still create their own implementation of the protocol, see the wiki for the link to the protocol.

And you can get here our test AI and GS using SCP as sample of how it works, except for the demonstration, they are of no use. Also the latest revision of the GS/AI Libs...

http://dev.openttdcoop.org/projects/scr ... ow/package
We're at a point where comments and feedback would help us, hence that post :)

Edit: i have remove the files attachments, as versions evolve fast, it's better to grab them from http://dev.openttdcoop.org/projects/scr ... ow/package
Last edited by krinn on 21 May 2012 09:52, edited 1 time in total.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script Communication Protocol

Post by Zuu »

The documentation is getting better. I've completed the first version of an API documentation of the library. I plan to upload a demo of TransportGoals with NoGo support and I also got a CluelessPlus version that can talk with TransportGoals (but not yet react on the goal).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: Script Communication Protocol

Post by Hyronymus »

Krinn and Zuu, the two of you deserve a statue in a town of your choice :bow: .
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Script Communication Protocol

Post by planetmaker »

Hyronymus wrote:Krinn and Zuu, the two of you deserve a statue in a town of your choice :bow: .
Unfortunately I fail to fit 'Krinn' onto the statue...
Attachments
statue_zuu.png
statue_zuu.png (1.06 KiB) Viewed 11918 times
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: Script Communication Protocol

Post by Hyronymus »

planetmaker wrote:
Hyronymus wrote:Krinn and Zuu, the two of you deserve a statue in a town of your choice :bow: .
Unfortunately I fail to fit 'Krinn' onto the statue...
Think outside the blue box :).
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Script Communication Protocol

Post by krinn »

thank you guys, if you know a place without birds :)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Script Communication Protocol

Post by planetmaker »

Here now the real thing [TM] with both names... take a close look at the statues ;-)

I wish to apologize for my quick and dirty graphics.
Attachments
statue.zip
source bundle
(19.3 KiB) Downloaded 275 times
statue.tar
NewGRF
(22.5 KiB) Downloaded 233 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script Communication Protocol

Post by Zuu »

I found two issues with the current version. If you transmit a string with underscores, the underscore characters do not get transmitted correctly. The other issue is that if you try to transmit -1, the SCP library crash.

I've informed krinn about the issue, but though that anyone trying to use the library should be aware of the issue too to not waste your time on this bug.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Script Communication Protocol

Post by TrueBrain »

1 word: wow.
The only thing necessary for the triumph of evil is for good men to do nothing.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Script Communication Protocol

Post by krinn »

I have upload the libraries for AI and GS on bananas what i think is a stable release. If you want a test AI and GS you can grab them from the url gave on first post as i won't upload them to bananas, because they are just tests and not real usable AI/GS.

Don't forget to add them as dependencies for your GS/AI if you use them.
Look out the wiki page for help or ask questions, and add your GS commands to the wiki so AI authors could implement them easy.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script Communication Protocol

Post by Zuu »

Unfortunately, there still seem to be some instability in this communication library.

Sometimes, but not always this happens:

On the GS side this was sent: (an array with the numbers presented in the red rectangle)
gs-sent.png
gs-sent.png (24 KiB) Viewed 11210 times

Code: Select all

local result = [for_company, date,  0, 0, 0,  0, 0, 0,  0, 0, 0];
// code that adds goal data to result array. (each pair of three values is a goal)
SCPLib.Answer(message, result);

On the AI side this is received:
ai-received.png
ai-received.png (23.37 KiB) Viewed 11210 times
Edit: The code used to print that message looks like this: (yes quick and dirty)

Code: Select all

		local s = "";
		if(message.Data != null)
		{
			for(local i = 0; i < message.Data.len(); i++)
			{
				if (i == 2) s+= " | ";
				else if (i == 2 + 3) s+= " | ";
				else if (i == 2 + 6) s+= " | ";
				else if (s != "") s+=", ";
				s += "" + message.GetData(i);
			}
		}
		AILog.Info("Server gave transport goal: " + s);
		AIController.Break("");

Also I get the "Hole in message" warning/error from time to time in a very non-predictable way. If I load a save game multiple times I get different results. My guess is that the amount of time that the game is paused (= GS runs but not AI) somehow have an impact on if this problem happen or not. But its no extreme differences. Its more about open in-game windows and then unpause game or unpause game first and then open some in-game windows. Or be quick or slow about hitting unpause etc. and I have not yet to see a pattern in when it happens and when not. (maybe the only pattern so far is that I have only seen it when loading a game, but most of my testing is based upon re-loading a save-game and make adjustments in my source code before reloading)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Script Communication Protocol

Post by Alberth »

In regular network programming, one of the pitfalls is the assumption that messages arrive in one piece.
I don't know how you communicate, but it may be useful to check what promises the used network calls give you.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Script Communication Protocol

Post by krinn »

That's what i've done Alberth, and funny, it was that : messages doesn't arrive in one piece :)

for the communcation: the basics are encode in a define charset (limited by openttd) a message, that is then cut into 31 chars pieces (sign length restriction) and build the signs for a given company. We have a protocol.txt that explain it, but honeslty outdate, something that should be update, but time...
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Script Communication Protocol

Post by Alberth »

Not updating docs may seem to give you time, but that's not true. One day you'll have to return to some issue, and then you spend hours to retrieve the information you'd now write in a fraction of that time.

Another possibility is that someone else might want to know how it works, and then you have to spend time to explain it all, while otherwise you could just point at the doc.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Script Communication Protocol

Post by krinn »

The doc has been update (maybe because Zuu isn't as lazzy as me).
Only protocol isn't, something i will do, but as it change a lot while we met problems, it wasn't that stable to document it as it should.
But i will, as it seems stable now (version change a lot, but protocol seems fine)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: NoCarGoal SCP Client (AI Library)

Post by krinn »

Kogut wrote: Why AIAI is used as name for something? I hope that there is a possibility to use name that is not the same as my AI, this collision may end quite confusing.
Because it was made like that for a futher extension (that may never appears because of lack of interrest from anyone).
SCP is design to do AI<>GS, but also for AI<>AI.
So to identify an AI from another AI that would try speak with it, the shortname (that should be uniq) is the best name to use. And like that an AI with SCP not handling AI<>AI will still be able to "hear" another one handling it (but not speak with it).
That name is use internally by the SCP library.
So it was a need to avoid incompatibility later.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Script Communication Protocol

Post by Kogut »

Why aiai is used as name for something? I hope that there is a possibility to use name that is not the same as my AI, this collision may end quite confusing.

Why it is necessary to provide version number of AI? As GetVersion from info.nut refuses to work in other files it requires manual update after every version change of AI. And is it really necessary to provide this data? It seems to be unused anywhere, except in log statements.

minor problem in Script_Communication_for_AI-45\main.nut:

Code: Select all

	SCPLog.Info("Script Communcation Protocol: version: "+_SCPLib_Share.LibVersion+" - API: "+_SCPLib_Share.LibAPIVersion+"
"Communcation" should be "Communication"
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: NoCarGoal SCP Client (AI Library)

Post by Zuu »

I can now think that possible the company Id would be better if there are multiple AIs of the same ShortName in the game. However, care has to be taken if it changes the protocol so that old/new clients either work or fail hard with an error.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Script Communication Protocol

Post by krinn »

Kogut wrote:"Communcation" should be "Communication"
Thanks. It will get fix if any version goes out, but i won't pubish one just for this ;)

Other questions are already answer on the other thread.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Script Communication Protocol

Post by Zuu »

krinn wrote:Other questions are already answer on the other thread.
For your information: those answers has now been moved here by a moderator.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests