LiminaliaLiminalia
How-to: Make your first command

Make your first command

Open in Claude (new tab)
On this page

Effects that the standard commands don’t offer can be added as your own commands with a plugin. Here you make @caption, which shows a short text (a caption) in the middle of the screen, and go as far as using it in the script.

The examples on this page use the project you make in the tutorial, “Shiori of the Library.”

Plugins are written in TypeScript. Have a text editor for editing the files (such as VS Code) ready.

Create a new plugin

  1. Click “Plugins” at the top of the screen, and choose “All plugins” in the left panel.
  2. In the “Create new” section, enter the plugin name caption. Names can use lowercase letters, digits and -, and must start with a lowercase letter.
  3. Among the features to include, check “Commands” and “Rendering,” and clear “Studio.” “Rendering” is the part that shows pictures and text on the game screen.
  4. Click “Create.”
"Create new" on the Plugins screen, with caption entered as the name and Commands and Rendering checked.

A plugin with a small working sample is created in plugins/caption in the project and added to plugins in liminalia.json. The list shows “Loaded after a restart,” so click “Restart” at the top.

caption added to the list, with "Plugins changed. They take effect after a restart" and a "Restart" button at the top.

The files it creates

plugins/caption contains the following three files. You can open this folder with “Open folder” in the list.

FileContents
package.jsonThe plugin’s name, and which file holds what
src/commands.tsThe command definition, with its name, description and parameters
src/web.tsThe rendering: what to show on the screen when the command runs

Even as it is, the sample works as a command: write @caption-hello Hello and “Hello” appears on the screen. From here, you rewrite this sample into @caption.

Define the command

Rewrite src/commands.ts as follows.

import { defineCommandPlugin, t, type CommandDefinition } from "@liminalia/sdk";

/** A command that shows a short text (a caption) in the middle of the screen. */
const caption: CommandDefinition = {
  name: "caption",
  summary: "Show a caption (a short text in the middle of the screen, shown for time and then removed)",
  positional: ["text"],
  params: {
    text: t.required(t.text("Text to show")),
    time: t.duration("How long to show it", "2s"),
    wait: t.bool("Don't go on until it disappears", true),
  },
  example: '@caption "Three days later"',
  waits: true,
  category: "screen",
  keywords: ["subtitle", "title card"],
};

export default defineCommandPlugin({ name: "caption", commands: [caption] });
ItemMeaning
nameThe command name you write in the script (@caption). Use lowercase letters, digits and -
summaryThe description of the command. The text before the first parenthesis becomes the name of the part in the parts panel
positionalParameters you can pass without a name. In @caption "Three days later", “Three days later” becomes text
paramsThe parameters, with their types, descriptions and defaults
exampleAn example of how to write it. It appears in the parameter panel and the command reference
waitsWhether to wait for the effect to finish before going on to the next line
categoryWhere to list it in the parts panel. screen is “Backgrounds and screen.” If you leave it out, it’s listed under “Custom commands”
keywordsWords besides the name that find it when you search the parts panel

Choose the parameter types from t.text (text shown to players, which gets translated), t.string (a string), t.number (a number), t.bool (true or false), t.duration (a time such as 500ms or 2s) and others. When you write the types, a wrong value such as time=fast is reported by the check before you play.

Write the rendering

Rewrite src/web.ts as follows.

import { defineWebPlugin } from "@liminalia/sdk/web";

/** Rendering for @caption. Shows the text for time, then removes it. */
export default defineWebPlugin({
  name: "caption",
  extensions: {
    renderers: {
      caption: async (ctx, args, wait) => {
        const el = document.createElement("div");
        el.textContent = String(args.text);
        Object.assign(el.style, {
          position: "absolute", left: "50%", top: "40%", translate: "-50% 0",
          padding: "12px 32px", background: "rgb(0 0 0 / 0.6)", color: "#fff", fontSize: "32px", borderRadius: "8px",
        });
        ctx.layers.overlay.append(el);
        // ctx.time returns 0 while skipping (the effect ends instantly)
        const shown = el
          .animate([{ opacity: 0 }, { opacity: 1, offset: 0.15 }, { opacity: 1, offset: 0.85 }, { opacity: 0 }], { duration: ctx.time(Number(args.time)) })
          .finished.catch(() => {})
          .then(() => el.remove());
        if (wait) await shown;
      },
    },
  },
});
  • caption in renderers is called when @caption runs. args holds the parameters, with defaults filled in. The time (time) is a number of milliseconds.
  • ctx.layers.overlay is a layer that sits in front of the message window.
  • For the length of an effect, pass it to ctx.time() and use the value it returns. While skipping, it returns 0, and the effect ends instantly.
  • When wait is true, the story doesn’t go on to the next line until the caption disappears.

Use it in the script

After saving the files, click “Refresh” (⌘⇧R) in the ”…” (More) menu at the top right of the screen. Studio notices the plugin change, restarts and loads the new command. If you opened the project with lim studio, start lim studio again.

  1. In the block view of the “Script” screen, select the line just before where you want the caption.
  2. Type “caption” in the box at the top of the parts panel to find the “Show a caption” part. Double-click it to add it.
  3. In text in the parameter panel on the right, enter the text to show.
The parts panel searched for "caption," "Show a caption" added, and "After school" entered in text in the right panel.

In the code view, write it as follows. When you type after @, caption appears in the suggestions too.

@bg library.webp
@caption "After school"
After school, the library was quieter than usual.
@caption "Three days later" time=3s

In a test play, check that the caption appears, disappears, and the story goes on to the next line.

The game screen, with the caption "After school" in the middle of the library background.

Check on the command line

If you use lim, run the following commands in the project folder to see how your command is handled.

lim check --lang en      # reports @caption without text, or values like time=fast, with their line positions
lim reference --lang en  # @caption is listed under "Commands of the caption plugin" in the command reference
lim trace start          # runs without a screen and prints the parameters passed to @caption

For example, if you write just @caption, lim check --lang en reports “@caption requires text” and suggests @caption "Three days later" as a fix.

A command like this caption, which just shows something and then removes it, can be made without worrying about saving and loading. A command that shows something that stays on the screen (a stamp, or an image left in place) also needs code that records its state and rebuilds the screen on load. How to write that is in Writing plugins, which uses @stamp, a command that puts a stamp on the screen, as its example.

Commands used on this page

@bg