Trying to load a GameScript for a Dedicated Server

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
gregdek
Engineer
Engineer
Posts: 2
Joined: 13 Dec 2020 22:46

Trying to load a GameScript for a Dedicated Server

Post by gregdek »

I'm working on some code to run a tournament of AIs, and as part of that I'd like to have a gamescript that does some logging. I'm trying to run the gamescript against a dedicated server.

I've got AIs working, and that's fine. But I've got a dead-simple Gamescript, and it's failing silently and I can't figure out why.

Here's the info.nut:

Code: Select all

class Arbiter extends GSInfo {
  function GetAuthor()      { return "gregdek"; }
  function GetName()        { return "Arbiter"; }
  function GetDescription() { return "An arbiter of AI-only games"; }
  function GetVersion()     { return 1; }
  function GetDate()        { return "2021-02-02"; }
  function CreateInstance() { return "Arbiter"; }
  function GetShortName()   { return "ARBX"; }
  function GetAPIVersion()  { return "1.9"; }
  function GetSettings();
}

/* Tell the core we are a GS */
RegisterGS(Arbiter());
And here's the main.nut:

Code: Select all

class Arbiter extends GSController 
{
    constructor()
}

function Arbiter::Start()
{
  GSLog.Info("[arbi] I am here!");
  GSController.Sleep(1);
  while (true) {
    // we just wait every 10 ticks and ping
    GSLog.Info("[arbi] I am still here!");
    GSController.Sleep(10);
  }
}
And here's how I'm invoking it in openttd.cfg:

Code: Select all

[game_scripts]
arbiter = foo=1
And nothing. I've got debug logs turned up to 9 across the board, and I know that OpenTTD finds the tar file and the .nut files, but then it's just silent failure.

Any hints? I'm tearing my hair out. Thanks!
User avatar
Firrel
Engineer
Engineer
Posts: 119
Joined: 13 Aug 2019 17:06

Re: Trying to load a GameScript for a Dedicated Server

Post by Firrel »

You are missing semi collon after the constructor, the well known hair tearer :D
gregdek
Engineer
Engineer
Posts: 2
Joined: 13 Dec 2020 22:46

Re: Trying to load a GameScript for a Dedicated Server

Post by gregdek »

Firrel wrote: 03 Feb 2021 15:01 You are missing semi collon after the constructor, the well known hair tearer :D
Sadly, that is not the problem. I added the semicolon, no luck. :)

I mean, I'm sure it's something dumb like that -- maybe I'm not invoking it properly in the config file -- but there's no hints anywhere in the logs at all, nothing, even with -d 9. I know the dedicated server sees the tarball

Code: Select all

dbg: [misc] Found dir in tar: arbiter/
dbg: [misc] Found file in tar: arbiter/info.nut (524 bytes, 3072 offset)
dbg: [misc] Found file in tar: arbiter/main.nut (286 bytes, 5632 offset)
dbg: [misc] Found tar '/home/openttd/content_download/game/arbiter.tar' with 2 new files
...but then: nothing.
User avatar
Firrel
Engineer
Engineer
Posts: 119
Joined: 13 Aug 2019 17:06

Re: Trying to load a GameScript for a Dedicated Server

Post by Firrel »

The semicolon was a problem, without it, it was crashing.

Tested it in a dedicated server with a visible element, pauses, and it was working well.

Code: Select all

class Arbiter extends GSController 
{
    constructor();
}

function Arbiter::Start()
{
  GSLog.Info("[arbi] I am here!");
  GSController.Sleep(10);

  while (true) {
    // we just wait every 10 ticks and ping
    GSLog.Info("[arbi] I am still here!");
    GSController.Sleep(100);
    GSGame.Pause();
    GSController.Sleep(100);
    GSGame.Unpause();
  }
}

Code: Select all

[game_scripts]
Arbiter = 
Snímka.PNG
Snímka.PNG (9.81 KiB) Viewed 1194 times
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 12 guests