Creating your first module

This walks through building a module from nothing. Read Anatomy of a module first — this page assumes you know what the pieces are.

1. Create the module directory

Modules live under the SDK's module directory:

/userland/sdk/module/installed

Create a directory there named for your module.

2. Declare metadata

Give the module a title, a description and an author. The description is what an operator reads when deciding whether to install it, so describe the behaviour, not the name.

3. Set a version

Start at whatever number you like and increment it on every published change. GameDash compares this value to decide that an update is available.

4. Declare what you support

In properties.json, set supportedOperatingSystem to the platforms you have actually tested. Use the linux shorthand to cover every supported distribution, or name specific platforms:

{
    "supportedOperatingSystem": [ "linux", "windows" ]
}

Declaring support you do not have does not make the game work — it makes it fail later, at instance creation, on a node that cannot run it.

5. Declare your resources

List the resources the module implements. Anything you leave out falls back to default behaviour, so start with the minimum: for a game, that is usually process handling.

6. Write the resource class

Each resource extends the abstract template for its type. For a service module's process resource, that means implementing start(), stop(), restart() and isOnline().

Resolve the instance from the gateway in the constructor and keep it:

public function __construct( Gateway\Gateway $Gateway ) {

    $instanceId = $Gateway->getParameters()->get('instance.id')->getValue();

    $this->Instance = Instance\Instances::get( $instanceId );

}

Then implement the lifecycle against it — creating a child process, setting the executable and arguments, and spawning it. Service modules covers what each method is responsible for, and Example service module shows a complete implementation.

7. Try it

Install the module, create an instance against it, and start it. The things that usually go wrong first:

  • The resource never runs — the class is not extending its template.
  • The game is not offered on a nodesupportedOperatingSystem does not include that node's platform.
  • It starts and immediately stops — the executable or arguments are wrong. Check the console output; the daemon retains recent lines for replay.

Next