Skip to content

Latest commit

 

History

History
4094 lines (2495 loc) · 99.9 KB

File metadata and controls

4094 lines (2495 loc) · 99.9 KB

Mucklet Script Documentation

Overview

Guides
Script examples
Entry points
    onActivate
    onRoomEvent
    onMessage
    onCharEvent
    onExitUse
    onCommand
    onRequest
API references

Mucklet scripts are written in AssemblyScript, a strictly typed TypeScript-like language. For more info on AssemblyScript, its types, and standard library, see:

    🔗 AssemblyScript Concepts

The standard library of AssemblyScript has been extended with classes and functions to interact with Mucklet realms. See the API references for a complete list of those extensions.

Guides

Script examples

Script file Description
ambience.ts A script showing ambient descriptions with random time intervals.
day_and_night.ts A script cycling between a "day" and "night" room profile based on real time.
intercom_inside.ts An intercom script allowing communication with another room running the intercom_outside.ts script.
intercom_outside.ts An intercom script allowing communication with another room running the intercom_inside.ts script.
lock_inside.ts A script that locks a door preventing others from using an exit in the room running the lock_outside.ts script.
lock_outside.ts A script that prevents characters from using an exit locked by the lock_inside.ts script.
secret_exit.ts A script that reveals a secret passage when the password "tapeworm" is spoken.
vip_list.ts A script that manages a list of VIP characters, requested by another room running the vip_guard.ts script.
vip_guard.ts A script that prevents characters from using an exit unless they are listed as VIP character by the vip_list.ts script.

Entry points

The script entry points are exported functions that are called on different types of events, such as the script activating, someone entering a room, or a command being called.

The only entry point that is required is onActivate.

onActivate

onActivate is called each time a script is activated or updated. It is primarily used to call Script.listen, Room.listen, or Room.addCommand, to have the script listening for events, messages, or commands.

When a script is updated, previous listeners, (e.g. Room.listen), commands (Room.addCommand), or scheduled posts (Script.post with delay), will be removed, and onActivate will be called again on the new script version.

Examples

// Send a describe to the room and log a message to the console on activation.
export function onActivate(): void {
    Room.describe("Hello, world!");
    console.log("Hello, console!");
}

onRoomEvent

onRoomEvent is called when an event occurs in the room, such as a say, arrive, or sleep. Room.listen must have been called earlier to start listening to room events, usually in the onActivate function.

Parameters

  • addr (string): Address of this script instance receiving the event.
  • ev (string): Event encoded as a json string.

Examples

// Check the event type and decode the event.
export function onRoomEvent(
    addr: string,
    ev: string,
): void {
    const eventType = Event.getType(ev);
    if (eventType == 'say') {
        const say = JSON.parse<Event.Say>(ev);
        // Handle the say event
    }
}

onMessage

onMessage is called when another script sends a message to this script, using Script.post or Script.broadcast. Script.listen must have been called earlier to start listening to messages, usually in the onActivate function.

Parameters

  • addr (string): Address of this script instance receiving the message.
  • topic (string): Topic of the message. Determined by the sender.
  • data (string | null): JSON encoded data of the message or null. Determined by the sender.
  • sender (string): Address of the sending script instance.

Examples

// Receive a message from another script to change room profile
export function onMessage(
    addr: string,
    topic: string,
    data: string | null,
    sender: string,
): void {
    if (topic == "changeProfile") {
        Room.setProfile(JSON.parse<string>(data))
    }
}

onCharEvent

onCharEvent is called when a character enters a room, leaves a room, or changes any of its properties while inside the room. Room.listenCharEvent must have been called earlier to start listening to character events, usually in the onActivate function.

Parameters

  • addr (string): Address of this script instance receiving the event.
  • charId (string): ID of character.
  • after (string | null): Character state after the event encoded as a json string, or null if the character left the room.
  • before (string | null): Character state before the event encoded as a json string, or null if the character entered the room.

Examples

// Output to log when a character arrives or leaves
export function onCharEvent(
    addr: string,
    charId: string,
    after: string | null,
    before: string | null,
): void {
    if (after == null && before != null) {
        // If after is null, the character left
        const char = JSON.parse<Room.Char>(before);
        console.log(`${char.name} left.`)
    }
    if (before == null && after != null) {
        // If before is null, the character arrived
        const char = JSON.parse<Room.Char>(after);
        console.log(`${char.name} arrived.`)
    }
}

onExitUse

onExitUse is called when a character tries to use an exit. Room.listenExit must have been called earlier to start listening to exit use, usually in the onActivate function. The script should call either ExitAction.cancel or ExitAction.useExit to determine what should happen. If neither method is called, the action will timeout after 1 second, automatically canceling the exit use with a default message.

Parameters

  • addr (string): Address of this script instance receiving the event.
  • cmdAction (ExitAction): Exit action object.

Examples

// Prevent anyone from using an exit
export function onExitUse(
    addr: string,
    exitAction: ExitAction,
): void {
    exitAction.cancel("The door seems to be locked.");
}

onCommand

onCommand is called when a character uses a custom command. Room.addCommand must have been called earlier to register the command, usually in the onActivate function. The script may send a response to the caller using either CmdAction.info, CmdAction.error, or CmdAction.useExit, but it is not required. The response must be sent within 1 second from the call.

Parameters

  • addr (string): Address of this script instance receiving the action.
  • cmdAction (CmdAction): Command action object.

Examples

// Adding a ping command on activation
export function onActivate(): void {
    Room.addCommand("ping", new Command("send ping", "Sends a ping to the script.");
}

// Adds a "send ping" command that responds with an info message
export function onCommand(
    addr: string,         // Address of this script instance receiving the action.
    cmdAction: CmdAction, // Command action object.
): void {
    cmdAction.info("Pong!");
}

onRequest

onRequest is called when another script sends a request to this script, using Script.request. Script.listen must have been called earlier to start listening to requests, usually in the onActivate function.

Parameters

  • addr (string): Address of this script instance receiving the request.
  • request (Request): Request object.

Examples

// Receive a request from another script and send a response.
export function onRequest(
    addr: string,
    request: Request,
): void {
    if (request.topic == "getValue") {
        // Parse any data passed as arguments.
        const key = request.parseData<string>()
        const value = Store.getString(key)
        // Send a response to the request
        request.reply(value)
    }
}

API references

Type aliases
    type Duration
    type ID
    type Timestamp
Enums
    enum CharState
    enum CommandFlag
    enum ExitIcon
    enum ExitNav
    enum IdleLevel
    enum RPState
Interfaces
    interface CommandField
        method getType
        method getDesc
        method getOpts
Classes
    class CmdAction
        method info
        method error
        method useExit
    class Command
        method field
        method setPriority
        method setRestricted
        method setUnlisted
        method json
    class ExitAction
        method useExit
        method cancel
    class Request
        method parseData
        method reply
        method error
    class Response
        method isError
        method parseResult
Namespaces
    Event namespace
    Field namespace
    FieldValue namespace
    JSON namespace
    Room namespace
    Script namespace
    Store namespace

Event namespace

Event functions
    function Event.getType
Event classes
    class Event.Action
    class Event.Arrive
    class Event.Base
    class Event.BaseCharMethodMsg
    class Event.BaseCharMsg
    class Event.BaseCharPoseMsg
    class Event.Char
    class Event.Describe
    class Event.Leave
    class Event.OOC
    class Event.Pose
    class Event.Roll
    class Event.RollResult
    class Event.Say
    class Event.Sleep
    class Event.Wakeup

Field namespace

Field classes
    class Field.Bool
        method getType
        method getDesc
        method getOpts
    class Field.Char
        method getType
        method getDesc
        method getOpts
        method setInRoom
        method setState
    class Field.Float
        method getType
        method getDesc
        method getOpts
        method setMin
        method setMax
    class Field.Integer
        method getType
        method getDesc
        method getOpts
        method setMin
        method setMax
    class Field.Keyword
        method getType
        method getDesc
        method getOpts
        method setRemoveDiacritics
        method setMinLength
        method setMaxLength
    class Field.List
        method getType
        method getDesc
        method getOpts
        method addItem
        method setItems
    class Field.Text
        method getType
        method getDesc
        method getOpts
        method setSpanLines
        method setSpellCheck
        method setFormatText
        method setMinLength
        method setMaxLength

FieldValue namespace

FieldValue classes
    class FieldValue.Bool
    class FieldValue.Char
    class FieldValue.Float
    class FieldValue.Integer
    class FieldValue.Keyword
    class FieldValue.List
    class FieldValue.Text

JSON namespace

JSON enums
    enum JSON.Types
JSON functions
    function JSON.parse
    function JSON.stringify
JSON classes
    class JSON.Box
        method set
        method from
        method toString
    class JSON.Obj
        method set
        method get
        method has
        method delete
        method keys
        method values
        method toString
        method from
    class JSON.Raw
        method set
        method toString
        method from
    class JSON.Value
        method empty
        method from
        method set
        method get
        method as
        method toString

Room namespace

Room functions
    function Room.addCommand
    function Room.canEdit
    function Room.charIterator
    function Room.describe
    function Room.exitIterator
    function Room.getChar
    function Room.getDetails
    function Room.getExit
    function Room.getExitById
    function Room.getExitOrder
    function Room.listen
    function Room.listenCharEvent
    function Room.listenExit
    function Room.privateDescribe
    function Room.profileIterator
    function Room.removeCommand
    function Room.setExit
    function Room.setRoom
    function Room.sweepChar
    function Room.unlisten
    function Room.unlistenCharEvent
    function Room.unlistenExit
    function Room.useProfile
Room classes
    class Room.Char
    class Room.CharIterator
        method next
        method rewind
        method getID
        method isValid
        method close
        method getChar
    class Room.Exit
    class Room.ExitIterator
        method next
        method rewind
        method getID
        method isValid
        method close
        method getExit
    class Room.MoveMsgs
    class Room.Profile
    class Room.ProfileIterator
        method next
        method rewind
        method getID
        method isValid
        method close
        method getProfile
    class Room.RoomDetails

Script namespace

Script functions
    function Script.broadcast
    function Script.cancelPost
    function Script.getChar
    function Script.listen
    function Script.post
    function Script.request
    function Script.unlisten
Script classes
    class Script.Char

Store namespace

Store functions
    function Store.deleteKey
    function Store.getBuffer
    function Store.getString
    function Store.readOnly
    function Store.setBuffer
    function Store.setString
    function Store.totalBytes
Store classes
    class Store.Iterator
        method withPrefix
        method inReverse
        method next
        method seek
        method rewind
        method getKeyString
        method getKeyBuffer
        method getValueString
        method getValueBuffer
        method isValid
        method isValidForPrefix
        method close

Type aliases

type Duration

type Duration = i64

Duration in milliseconds.


type ID

type ID = string

ID for in game entities such as characters, rooms, and areas.


type Timestamp

type Timestamp = i64

Timestamp as a UTC timestamp in milliseconds.

Enums

enum CharState

const enum CharState {
    Asleep = 0,
    Awake  = 1,
    Dazed  = 2,
    Any    = 255,
}

States that a character may have.


enum CommandFlag

const enum CommandFlag {
    None       = 0,
    Restricted = 1,
    Unlisted   = 2,
}

Command flag.


enum ExitIcon

const enum ExitIcon {
    None      = 0,
    North     = 1,
    NorthEast = 2,
    East      = 3,
    SouthEast = 4,
    South     = 5,
    SouthWest = 6,
    West      = 7,
    NorthWest = 8,
    Up        = 9,
    Down      = 10,
    In        = 11,
    Out       = 12,
}

Exit navigation icon.


enum ExitNav

const enum ExitNav {
    None      = 0,
    North     = 1,
    NorthEast = 2,
    East      = 3,
    SouthEast = 4,
    South     = 5,
    SouthWest = 6,
    West      = 7,
    NorthWest = 8,
}

Exit navigation directions.


enum IdleLevel

const enum IdleLevel {
    Asleep   = 0,
    Active   = 1,
    Idle     = 2,
    Inactive = 3,
}

Idle levels that a character may have.


enum RPState

const enum RPState {
    None = 0,
    LFRP = 1,
}

Roleplaying state that a character may have.

Interfaces

interface CommandField


method CommandField.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method CommandField.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method CommandField.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

Classes

class CmdAction

CmdAction is a command action triggered by a character.

class CmdAction properties

  • actionId (i32): Action ID
  • char (Event.Char): Character performing the action
  • keyword (string): Command keyword
  • data (string): Command data in JSON format.

method CmdAction.info

info(msg: string): void

Responds to the command action with an info message.

Parameters

  • msg (string): Info message. It may be formatted with info formatting and span multiple paragraphs.

method CmdAction.error

error(msg: string): void

Responds to the command action with an error message.

Parameters

  • msg (string): Error message. It may be formatted and span multiple paragraphs.

method CmdAction.useExit

useExit(exitId: ID): void

Responds to the command action by making the character use an exit.

The exit may be hidden or inactive. May not be used in combination with info or error.

Parameters

  • exitId (ID): Exit ID.

class Command

Command class is a representation of a custom command, and is used as an argument when calling Room.addCommand.

See also: Writing scripts - Custom commands

new Command(pattern: string, desc: string = "")

Creates a new instance of the Command class.

Parameters

  • pattern (string)
  • desc (string)

class Command properties

  • priority (u32)
  • flags (u32)
  • pattern (string)
  • desc (string)

method Command.field

field(key: string, def: CommandField): Command

Sets the definition for a command field.

Parameters

  • key (string): Field as found in command pattern.
  • def (CommandField): Field definition.

Returns

  • (Command): This instance, allowing method chaining.

method Command.setPriority

setPriority(priority: u32): Command

Sets command priority.

Parameters

  • priority (u32): Priority for sort order (descending) and when two or more commands match the same input. Higher priority is selected first.

Returns

  • (Command): This instance, allowing method chaining.

method Command.setRestricted

setRestricted(): Command

Sets the command as restricted, only accessible to character able to edit the room.

Returns

  • (Command): This instance, allowing method chaining.

method Command.setUnlisted

setUnlisted(): Command

Sets the command as unlisted, not showing up in the interface. It can still be used, and will be listed using list commands.

Returns

  • (Command): This instance, allowing method chaining.

method Command.json

json(): string

Converts the command into a JSON structure.

Returns

  • (string)

class ExitAction

ExitAction is an action representing an intercepted use of an exit.

It is passed to onExitUse entry point when a character tries to use an exit that is being listen to with Room.listenExit.

class ExitAction properties

  • actionId (i32): Action ID
  • charId (ID): Character ID
  • exitId (ID): Exit ID

method ExitAction.useExit

useExit(exitId: ID | null = null): void

Makes the character use an exit. If exitId is null, the character is sent through the exit that they originally tried to use.

The exit may be hidden or inactive.

Parameters

  • exitId (ID | null): Exit ID or null for the originally used exit.

method ExitAction.cancel

cancel(msg: string | null = null): void

Cancels a character's attempt to use an exit and shows them an info message instead. If msg is null, the default exit timeout message will be shown.

Parameters

  • msg (string | null): Info message to show, or default message if null.

class Request

Request is a request sent from another script.

class Request properties

  • actionId (i32): Action ID
  • topic (string): Request topic
  • data (string): Request data encoded as JSON.
  • sender (string): Request sender address.

method Request.parseData

parseData<T>(): T

Parses the data into a value of type T.

Returns

  • (T)

method Request.reply

reply(result: string | null = null): void

Responds to the request with a reply containing JSON encoded result.

Parameters

  • result (string | null): Reply data encoded as JSON.

method Request.error

error(msg: string): void

Responds to the request with an error message.

Parameters

  • msg (string): Error message.

class Response

Response is a response to a request sent by the script.

class Response properties

  • result (string | null): Result encoded as JSON.
  • error (string | null): Error string or null on no error.

method Response.isError

isError(): boolean

Returns true if it is an error response by checking that the error property is not a null value.

Returns

  • (boolean)

method Response.parseResult

parseResult<T>(): T

Parses the result into a value of type T.

Returns

  • (T)

Namespaces

Event functions

function Event.getType

Event.getType(ev: string): string

Get event type from a json encoded event.

Parameters

  • ev (string)

Returns

  • (string)

Event classes

class Event.Action

Action event.

class Event.Action properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.Arrive

Arrive event.

class Event.Arrive properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • method (string): Method

class Event.Base

Base event shared by all events.

class Event.Base properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.

class Event.BaseCharMethodMsg

Base event for message events by a character where a method is included, such as leave and arrive.

class Event.BaseCharMethodMsg properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • method (string): Method

class Event.BaseCharMsg

Base event for message events by a character, such as say, describe, pose, etc.

class Event.BaseCharMsg properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.BaseCharPoseMsg

Base event for message events by a character that may optionally be marked as a pose, such as OOC events.

class Event.BaseCharPoseMsg properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • pose (boolean): Message is a pose.

class Event.Char

Character object with name and ID.

class Event.Char properties

  • id (string): Character ID.
  • name (string): Character name.
  • surname (string): Character surname.

class Event.Describe

Describe event.

class Event.Describe properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.Leave

Leave event.

class Event.Leave properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • method (string): Method

class Event.OOC

OOC event.

class Event.OOC properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • pose (boolean): Message is a pose.

class Event.Pose

Pose event.

class Event.Pose properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.Roll

Roll event.

class Event.Roll properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.
  • total (i32): Roll total.
  • result (Array<Event.RollResult>): Roll result.
  • quiet (boolean): Quiet roll.

class Event.RollResult

Results in a roll event.

class Event.RollResult properties

  • type (string)
  • op (string): Modifier operator. Either "+" or "-".
  • count (i32): Dice count. Always 0 on type "mod".
  • sides (i32): Sides on dice. Always 0 on type "mod"
  • dice (Array<i32>): Roll value for each die. Always empty slice on type "mod"
  • value (i32): Modifier value. Always 0 on type "std".

class Event.Say

Say event.

class Event.Say properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.Sleep

Sleep event.

class Event.Sleep properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

class Event.Wakeup

Wakeup event.

class Event.Wakeup properties

  • id (string): Event ID.
  • type (string): Event type.
  • time (i64): Unix timestamp (milliseconds).
  • sig (string): Signature.
  • msg (string): Message.
  • char (Event.Char): Acting character.
  • puppeteer (Event.Char | null): Acting puppeteer.

Field classes

class Field.Bool

An bool field is used for boolean values.

new Field.Bool(desc: string = "")

Parameters

  • desc (string)

method Field.Bool.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Bool.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Bool.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

class Field.Char

A char field is used to enter the name of a character.

new Field.Char(desc: string = "")

Parameters

  • desc (string)

class Field.Char properties


method Field.Char.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Char.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Char.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.Char.setInRoom

setInRoom(): this

Sets inRoom flag, requiring the character to be in the room.

Returns

  • (this): This instance, allowing method chaining.

method Field.Char.setState

setState(state: CharState): this

Sets state that the character must be in. Default is CharState.Any.

Parameters

Returns

  • (this): This instance, allowing method chaining.

class Field.Float

A float field is used for decimal numbers.

new Field.Float(desc: string = "")

Parameters

  • desc (string)

class Field.Float properties

  • min (f64)
  • max (f64)

method Field.Float.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Float.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Float.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.Float.setMin

setMin(min: f64, inclusive: bool): this

Sets float min value. Must be smaller than (or equal if both are inclusive) to max value.

Parameters

  • min (f64): Min value of float.
  • inclusive (bool): Flag to tell if min value is inclusive (>=) on true, or exclusive (>) on false.

Returns

  • (this): This instance, allowing method chaining.

method Field.Float.setMax

setMax(max: f64, inclusive: bool): this

Sets float max value. Must be greater than (or equal if both are inclusive) to min value.

Parameters

  • max (f64): Max value of float.
  • inclusive (bool): Flag to tell if max value is inclusive (<=) on true, or exclusive (<) on false.

Returns

  • (this): This instance, allowing method chaining.

class Field.Integer

An integer field is used for whole numbers.

new Field.Integer(desc: string = "")

Parameters

  • desc (string)

class Field.Integer properties

  • min (i64)
  • max (i64)

method Field.Integer.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Integer.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Integer.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.Integer.setMin

setMin(min: i64): this

Sets integer min value. Must be smaller or equal to max value.

Parameters

  • min (i64): Min value of integer.

Returns

  • (this): This instance, allowing method chaining.

method Field.Integer.setMax

setMax(max: i64): this

Sets integer max value. Must be greater or equal to min value.

Parameters

  • max (i64): Max value of integer

Returns

  • (this): This instance, allowing method chaining.

class Field.Keyword

A keyword field is used for keyword names using a limited set of characters that will be transformed to lower case. By default, a keyword allows Letters, Numbers, Spaces, apostrophes ('), and dash/minus (-).

new Field.Keyword(desc: string = "")

Parameters

  • desc (string)

class Field.Keyword properties

  • removeDiacritics (boolean)
  • minLength (u32)
  • maxLength (u32)

method Field.Keyword.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Keyword.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Keyword.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.Keyword.setRemoveDiacritics

setRemoveDiacritics(removeDiacritics: boolean): this

Sets flag to remove diacritics from the keyword by decomposing the characters and removing any non-print characters and marker in the Mn Unicode category. Is false by default.

Parameters

  • removeDiacritics (boolean): Flag telling if diacritics should be removed.

Returns

  • (this)

method Field.Keyword.setMinLength

setMinLength(minLength: u32): this

Sets text min length. Must be smaller or equal to max length unless max length is set to zero (0).. Is 0 by default.

Parameters

  • minLength (u32): Min length of text.

Returns

  • (this)

method Field.Keyword.setMaxLength

setMaxLength(maxLength: u32): this

Sets text maximum length. Zero (0) means server max length. Is 0 by default.

Parameters

  • maxLength (u32): Max length of text.

Returns

  • (this)

class Field.List

A list field is used to select between a list of items. Items must be unique, not containing non-printable or newline characters, and be trimmed of leading, trailing, and consecutive spaces.

Items should not contain characters used as delimiters to continue the command.

new Field.List(desc: string = "")

Parameters

  • desc (string)

class Field.List properties

  • items (Array<string>)

method Field.List.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.List.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.List.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.List.addItem

addItem(item: string): this

Adds a single item to the list.

Parameters

  • item (string)

Returns

  • (this): This instance, allowing method chaining.

method Field.List.setItems

setItems(items: Array<string>): this

Sets an array of list items, replacing any previously set items.

Parameters

  • items (Array<string>): Array of list items.

Returns

  • (this): This instance, allowing method chaining.

class Field.Text

A text field is used for arbitrary text, such as messages, descriptions, or titles.

new Field.Text(desc: string = "")

Parameters

  • desc (string)

class Field.Text properties

  • spanLines (boolean)
  • spellCheck (boolean)
  • formatText (boolean)
  • minLength (u32)
  • maxLength (u32)

method Field.Text.getType

getType(): string

Returns the type of the command field.

Returns

  • (string)

method Field.Text.getDesc

getDesc(): string

Returns the help description of the command field.

Returns

  • (string)

method Field.Text.getOpts

getOpts(): string | null

Returns the options of the command field as a JSON encoded string.

Returns

  • (string | null)

method Field.Text.setSpanLines

setSpanLines(spanLines: boolean): this

Sets span lines flag. Is false by default.

Parameters

  • spanLines (boolean): Flag telling if the text can be spanned across multiple lines.

Returns

  • (this): This instance, allowing method chaining.

method Field.Text.setSpellCheck

setSpellCheck(spellCheck: boolean): this

Sets flag to spellCheck text. Is true by default.

Parameters

  • spellCheck (boolean): Flag telling if the text should be checked for spelling errors.

Returns

  • (this): This instance, allowing method chaining.

method Field.Text.setFormatText

setFormatText(formatText: boolean): this

Sets flag to format text while typing. Is false by default.

Parameters

  • formatText (boolean): Flag telling the text should be formatted while typing.

Returns

  • (this): This instance, allowing method chaining.

method Field.Text.setMinLength

setMinLength(minLength: u32): this

Sets text min length. Must be smaller or equal to max length unless max length is set to zero (0).. Is 0 by default.

Parameters

  • minLength (u32): Min length of text.

Returns

  • (this): This instance, allowing method chaining.

method Field.Text.setMaxLength

setMaxLength(maxLength: u32): this

Sets text maximum length. Zero (0) means server max length. Is 0 by default.

Parameters

  • maxLength (u32): Max length of text.

Returns

  • (this): This instance, allowing method chaining.

FieldValue classes

class FieldValue.Bool

class FieldValue.Bool properties

  • value (bool)

class FieldValue.Char

class FieldValue.Char properties

  • id (string): Character ID.
  • name (string): Character name.
  • surname (string): Character surname.

class FieldValue.Float

class FieldValue.Float properties

  • value (f64)

class FieldValue.Integer

class FieldValue.Integer properties

  • value (i64)

class FieldValue.Keyword

class FieldValue.Keyword properties

  • value (string)

class FieldValue.List

class FieldValue.List properties

  • value (string)

class FieldValue.Text

class FieldValue.Text properties

  • value (string)

JSON enums

enum JSON.Types

enum Types {
    Raw    = 0,
    U8     = 1,
    U16    = 2,
    U32    = 3,
    U64    = 4,
    F32    = 5,
    F64    = 6,
    Null   = 7,
    Bool   = 8,
    String = 9,
    Object = 10,
    Array  = 12,
    Struct = 13,
}

Enum representing the different types supported by JSON.

JSON functions

function JSON.parse

JSON.parse<T>(data: string): T

Parses valid JSON strings into their original format

JSON.parse<T>(data)

Parameters

  • data (string): string

Returns

  • (T): T

function JSON.stringify

JSON.stringify<T>(data: T, out: string | null = null): string

Serializes valid JSON data

JSON.stringify<T>(data)

Parameters

  • data (T): T
  • out (string | null)

Returns

  • (string): string

JSON classes

class JSON.Box

Box for primitive types

new JSON.Box<T>(value: T)

Parameters

  • value (T)

class JSON.Box properties

  • value (T)

method JSON.Box.set

set(value: T): Box<T>

Set the internal value of Box to new value

Parameters

  • value (T): T

Returns


method JSON.Box.from

from<T>(value: T): Box<T>

Creates a reference to a primitive type This means that it can create a nullable primitive

JSON.stringify<Box<i32> | null>(null);
// null

Parameters

  • value (T)

Returns


method JSON.Box.toString

toString(): string

Returns

  • (string)

class JSON.Obj

new JSON.Obj()

class JSON.Obj properties


method JSON.Obj.set

set<T>(key: string, value: T): void

Parameters

  • key (string)
  • value (T)

method JSON.Obj.get

get(key: string): Value | null

Parameters

  • key (string)

Returns


method JSON.Obj.has

has(key: string): bool

Parameters

  • key (string)

Returns

  • (bool)

method JSON.Obj.delete

delete(key: string): bool

Parameters

  • key (string)

Returns

  • (bool)

method JSON.Obj.keys

keys(): Array<string>

Returns

  • (Array<string>)

method JSON.Obj.values

values(): Array<Value>

Returns


method JSON.Obj.toString

toString(): string

Returns

  • (string)

method JSON.Obj.from

from<T>(value: T): Obj

Parameters

  • value (T)

Returns


class JSON.Raw

new JSON.Raw(data: string)

Parameters

  • data (string)

class JSON.Raw properties

  • data (string)

method JSON.Raw.set

set(data: string): void

Parameters

  • data (string)

method JSON.Raw.toString

toString(): string

Returns

  • (string)

method JSON.Raw.from

from(data: string): Raw

Parameters

  • data (string)

Returns


class JSON.Value

class JSON.Value properties

  • METHODS (Map<u32, u32>)
  • type (i32)

method JSON.Value.empty

empty(): Value

Creates an JSON.Value instance with no set value.

Returns


method JSON.Value.from

from<T>(value: T): Value

Creates an JSON.Value instance from a given value.

Parameters

  • value (T): The value to be encapsulated.

Returns


method JSON.Value.set

set<T>(value: T): void

Sets the value of the JSON.Value instance.

Parameters

  • value (T): The value to be set.

method JSON.Value.get

get<T>(): T

Gets the value of the JSON.Value instance.

Returns

  • (T): The encapsulated value.

method JSON.Value.as

as<T>(): T

Gets the value of the JSON.Value instance. Alias for .get()

Returns

  • (T): The encapsulated value.

method JSON.Value.toString

toString(): string

Converts the JSON.Value to a string representation.

Returns

  • (string): The string representation of the JSON.Value.

Room functions

function Room.addCommand

Room.addCommand(keyword: string, cmd: Command, priority: u32 = 0): void

Adds a custom command to the room.

Pattern is a string describing the general command structure, and may contain <Fields> parts. Any field defined in the pattern must have a corresponding field entry.

See also: Writing scripts - Custom commands

Parameters

  • keyword (string): Keyword for the command.
  • cmd (Command): Command to add.
  • priority (u32): Deprecated: Use Command.setPriority instead.

function Room.canEdit

Room.canEdit(charId: ID): boolean

Checks if a character is the owner of the room, or if the owner shares the same player as the character. It does not include admins or builders.

Parameters

  • charId (ID): Character ID.

Returns

  • (boolean)

function Room.charIterator

Room.charIterator(state: CharState = CharState.Any, reverse: boolean = false): CharIterator

Gets an iterator for the characters in the room that iterates from the character most recently entering the room.

Parameters

  • state (CharState): State of the characters to iterate over.
  • reverse (boolean): Flag to reverse the iteration direction, starting with the character that has been in the room the longest.

Returns


function Room.describe

Room.describe(msg: string): void

Sends a "describe" event to the current room instance.

Parameters

  • msg (string)

function Room.exitIterator

Room.exitIterator(): ExitIterator

Gets an iterator for the exits in the room. Order is undefined.

Returns


function Room.getChar

Room.getChar(charId: ID): Char | null

Gets a character in the room by ID.

Parameters

  • charId (ID): Character ID.

Returns


function Room.getDetails

Room.getDetails(): RoomDetails

Get detailed room information, such as description and settings.

Returns


function Room.getExit

Room.getExit(keyword: string): Exit | null

Gets an exit in the room by keyword.

Parameters

  • keyword (string): Exit keyword.

Returns


function Room.getExitById

Room.getExitById(exitId: ID): Exit | null

Gets an exit in the room by ID.

Parameters

  • exitId (ID): Exit ID.

Returns


function Room.getExitOrder

Room.getExitOrder(): Array<ID>

Gets the exit order of visible exits in the room as an array of ID values.

Returns

  • (Array<ID>)

function Room.listen

Room.listen(instance: string | null = null): boolean

Starts listening to room events on the current instance. If instance is set, it starts listening for events in that specific instance, or null for any room instance. Room events will be sent to onRoomEvent for the instance.

Parameters

  • instance (string | null): Instance or null for the non-instance.

Returns

  • (boolean): Returns true if a new listener was added, otherwise false.

function Room.listenCharEvent

Room.listenCharEvent(instance: string | null = null): boolean

Starts listening to char events in the room. If instance is set, it starts listening for events in that specific instance, or null for any room instance. Char events will be sent to onCharEvent for the instance.

Parameters

  • instance (string | null): Instance or null for any instance.

Returns

  • (boolean): True if a new listener was added, otherwise false.

function Room.listenExit

Room.listenExit(exitId: string | null = null): boolean

Starts listening to exit usage in the room, including any instance. If exitId is null, it acts as a wildcard to listen to any exit otherwise not being listened to specifically. Exit use events will be sent to onExitUse.

Only one script may listen to a given exit at any time. Only one script may listen to any exit with the null wildcard at any one time

Parameters

  • exitId (string | null): Exit ID or null for any exit.

Returns

  • (boolean): True if a new listener was added, otherwise false.

function Room.privateDescribe

Room.privateDescribe(msg: string, targetCharIds: Array<ID>): void

Sends a "privateDescribe" event to one or more target characters in the current room instance. A private describe can only be seen by the targeted characters.

Parameters

  • msg (string)
  • targetCharIds (Array<ID>)

function Room.profileIterator

Room.profileIterator(): ProfileIterator

Gets an iterator for the profiles for the room. Order is undefined.

Returns


function Room.removeCommand

Room.removeCommand(keyword: string): boolean

Removes a custom command, added by the script, from the room.

Parameters

  • keyword (string): Keyword for the command.

Returns

  • (boolean)

function Room.setExit

Room.setExit<T>(exitId: ID, fields: T): void

Set exit information.

The field parameter must an object that can be converted to a json object string with JSON.stringify, containing the following fields. Any other fields will be ignored.

{
    name?:        string,            // Name of the exit.
    keys?:        string[],          // Exit keywords used with the go command.
    leaveMsg?:    boolean,           // Message seen by the origin room. Usually in present tense (eg. "leaves ...").
    arriveMsg?:   boolean,           // Message seen by the arrival room. Usually in present tense (eg. "arrives from ...").
    travelMsg?:   boolean,           // Message seen by the exit user. Usually in present tense (eg. "goes ...").
    icon?:        ExitIcon,          // Icon for the exit.
    nav?:         ExitNav,           // Navigation direction for the exit.
    hidden?:      boolean,           // Flag telling if the exit is hidden, preventing it from being listed.
    inactive?:    boolean,           // Flag telling if the exit is inactive, preventing it from being listed and used.
    transparent?: boolean,           // Flag telling if the exit is transparent, allowing you to see awake characters in the target room.
    order?:       i32|i32u|i64|i64u, // Sort order of the exit with 0 being the first listed. Ignored if the exit is hidden or inactive.
}

Examples

// Setting a room exit to be active
Room.setExit(exitId, new Map<string, boolean>().set("inactive", false))

Parameters

  • exitId (ID): Exit ID.
  • fields (T): Exit fields to update as an object that can be stringified to json.

function Room.setRoom

Room.setRoom<T>(fields: T): void

Set room information.

The field parameter must an object that can be converted to a json object string with JSON.stringify, containing the following fields. Any other fields will be ignored.

{
    name?:                     string,   // Room name.
    desc?:                     string,   // Room description.
    isDark?:                   boolean,  // IsDark flags if other character can be seen or whispered to in the room.
    isQuiet?:                  boolean,  // IsQuiet flags if a room is quiet and won't allow communication.
    isHome?:                   boolean,  // IsHome flags if the room can be set as home by others.
    isTeleport?:               boolean,  // IsTeleport flags if the room can be added as a teleport node by others.
    isInstance?:               boolean,  // IsInstance flags if the room creates an instance.
    autosweep?:                boolean,  // Autosweep flags if sleepers in the room should be sent home automatically.
    autosweepDelay?:           Duration, // AutosweepDelay is the time in milliseconds until a sleeper is swept.
    customTeleportMsgs?:       boolean,  // CustomTeleportMsgs flags if the room uses custom teleport messages.
    overrideCharTeleportMsgs?: boolean,  // OverrideCharTeleportMsgs flags if the custom teleport messages should override any set character teleport messages.
    teleportLeaveMsg?:         object,   // Custom teleport message shown when someone teleports away from the room.
    teleportArriveMsg?:        object,   // Custom teleport message shown when someone teleports into the room.
    teleportTravelMsg?:        object,   // Custom teleport message shown to the character teleporting into the room.
}

Examples

// Setting the room to be dark
Room.setRoom(new Map<string, boolean>().set("isDark", true))

Parameters

  • fields (T): Room fields to update as an object that can be stringified to json.

function Room.sweepChar

Room.sweepChar(charId: ID, msg: string | null): void

Sweep a single character from the room by sending them home.

Parameters

  • charId (ID): Character ID.
  • msg (string | null): Message to show too the room when the character is teleported away. Defaults to other teleport messages.

function Room.unlisten

Room.unlisten(instance: string | null = null): boolean

Stops listening to room events on the current instance. If instance is provided, it stops listening for that specific instance, or null for the non-instance room.

Parameters

  • instance (string | null): Instance or null for the non-instance.

Returns

  • (boolean): True if a listener existed, otherwise false.

function Room.unlistenCharEvent

Room.unlistenCharEvent(instance: string | null = null): boolean

Stops listening to char events in the room. If instance is set, it stops listening for events in that specific instance, or null for any room instance.

Parameters

  • instance (string | null): Instance or null for any instance.

Returns

  • (boolean): True if a listener existed, otherwise false.

function Room.unlistenExit

Room.unlistenExit(exitId: string | null = null): boolean

Stops listening to exit usage in the room. If exitId is set, it stops listening for exit use for that specific exit, or null to stop listening for the the wildcard listener.

Parameters

  • exitId (string | null): Exit ID or null for any exit.

Returns

  • (boolean): True if a listener existed, otherwise false.

function Room.useProfile

Room.useProfile(keyword: string, safe: boolean = false): void

Switches to a stored room profile by profile key.

Parameters

  • keyword (string): Keyword for the stored profile.
  • safe (boolean): Flag to prevent the room's current profile to be overwritten by the stored profile, if it contains unstored changes.

Room classes

class Room.Char

Room character.

class Room.Char properties

  • id (ID): Character ID.
  • name (string): Character name.
  • surname (string): Character surname.
  • avatar (ID): Character avatar.
  • species (string): Character species.
  • gender (string): Character gender.
  • desc (string): Character description.
  • image (ID): Character image.
  • state (CharState): Character state.
  • idle (IdleLevel): Character idle status.
  • rp (RPState): Character RP state.

class Room.CharIterator

new Room.CharIterator(iterator: i32)

Constructor of the Iterator instance.

Parameters

  • iterator (i32)

class Room.CharIterator properties

  • iterator (i32)

method Room.CharIterator.next

next(): void

Advances the iterator by one. Always check isValid() after a next() to ensure have not reached the end of the iterator.


method Room.CharIterator.rewind

rewind(): void

Rewinds the iterator cursor all the way back to first position, which would be the smallest key, or greatest key if inReverse() was called.

Any iterator prefix passed to withPrefix() will be used on rewind. The iterator is rewound by default.


method Room.CharIterator.getID

getID(): ID

Returns the key string of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns


method Room.CharIterator.isValid

isValid(): boolean

Returns false when the cursor is at the end of the iterator.

Returns

  • (boolean)

method Room.CharIterator.close

close(): void

Closes the iterator. Any further calls to the iterator will cause an error. May be called multiple times.


method Room.CharIterator.getChar

getChar(): Char

Returns the current char. It will abort if the cursor has reached the end of the iterator.

Returns


class Room.Exit

Room exit.

class Room.Exit properties

  • id (ID): Exit ID.
  • keys (Array<string>): Exit keys.
  • name (string): Exit name.
  • icon (ExitIcon): Exit icon.
  • nav (ExitNav): Exit navigation direction.
  • leaveMsg (string): Leave message.
  • arriveMsg (string): Arrival message.
  • travelMsg (string): Travel message.
  • targetRoom (ID): Target room.
  • created (i64): Created timestamp.
  • hidden (boolean): Is hidden flag.
  • inactive (boolean): Is inactive flag.
  • transparent (boolean): Is transparent flag.

class Room.ExitIterator

new Room.ExitIterator(iterator: i32)

Constructor of the Iterator instance.

Parameters

  • iterator (i32)

class Room.ExitIterator properties

  • iterator (i32)

method Room.ExitIterator.next

next(): void

Advances the iterator by one. Always check isValid() after a next() to ensure have not reached the end of the iterator.


method Room.ExitIterator.rewind

rewind(): void

Rewinds the iterator cursor all the way back to first position, which would be the smallest key, or greatest key if inReverse() was called.

Any iterator prefix passed to withPrefix() will be used on rewind. The iterator is rewound by default.


method Room.ExitIterator.getID

getID(): ID

Returns the key string of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns


method Room.ExitIterator.isValid

isValid(): boolean

Returns false when the cursor is at the end of the iterator.

Returns

  • (boolean)

method Room.ExitIterator.close

close(): void

Closes the iterator. Any further calls to the iterator will cause an error. May be called multiple times.


method Room.ExitIterator.getExit

getExit(): Exit

Returns the current char. It will abort if the cursor has reached the end of the iterator.

Returns


class Room.MoveMsgs

Move messages used when entering or leaving a room.

class Room.MoveMsgs properties

  • leaveMsg (string)
  • arriveMsg (string)
  • travelMsg (string)

class Room.Profile

Room profile.

class Room.Profile properties

  • id (ID): Profile ID.
  • name (string): Profile name.
  • key (string): Profile key.
  • desc (string): Profile desc.
  • image (ID): Profile image.

class Room.ProfileIterator

new Room.ProfileIterator(iterator: i32)

Constructor of the Iterator instance.

Parameters

  • iterator (i32)

class Room.ProfileIterator properties

  • iterator (i32)

method Room.ProfileIterator.next

next(): void

Advances the iterator by one. Always check isValid() after a next() to ensure have not reached the end of the iterator.


method Room.ProfileIterator.rewind

rewind(): void

Rewinds the iterator cursor all the way back to first position, which would be the smallest key, or greatest key if inReverse() was called.

Any iterator prefix passed to withPrefix() will be used on rewind. The iterator is rewound by default.


method Room.ProfileIterator.getID

getID(): ID

Returns the key string of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns


method Room.ProfileIterator.isValid

isValid(): boolean

Returns false when the cursor is at the end of the iterator.

Returns

  • (boolean)

method Room.ProfileIterator.close

close(): void

Closes the iterator. Any further calls to the iterator will cause an error. May be called multiple times.


method Room.ProfileIterator.getProfile

getProfile(): Profile

Returns the current profile. It will abort if the cursor has reached the end of the iterator.

Returns


class Room.RoomDetails

Detailed room information.

class Room.RoomDetails properties

  • id (ID): Room ID.
  • name (string): Room name.
  • desc (string): Room description.
  • imageId (ID): Room image ID;
  • isDark (boolean): IsDark flags if other character can be seen or whispered to in the room.
  • isQuiet (boolean): IsQuiet flags if a room is quiet and won't allow communication.
  • isHome (boolean): IsHome flags if the room can be set as home by others.
  • isTeleport (boolean): IsTeleport flags if the room can be added as a teleport node by others.
  • isInstance (boolean): IsInstance flags if the room creates an instance.
  • autosweep (boolean): Autosweep flags if sleepers in the room should be sent home automatically.
  • autosweepDelay (i64): AutosweepDelay is the time in milliseconds until a sleeper is swept.
  • customTeleportMsgs (boolean): CustomTeleportMsgs flags if the room uses custom teleport messages.
  • overrideCharTeleportMsgs (boolean): OverrideCharTeleportMsgs flags if the custom teleport messages should override any set character teleport messages.
  • teleport (Room.MoveMsgs): Custom teleport messages.
  • created (i64): Created time.

Script functions

function Script.broadcast

Script.broadcast(topic: string, data: string | null = null): void

Broadcasts a message to all scripts listening to this script. Other room scripts in the same room listening to any message will also receive the message. The receiving script will get the message through the onMessage entry point.

To get other scripts to listen for broadcast, see Script.listen.

Parameters

  • topic (string): Message topic. May be any kind of string.
  • data (string | null): Additional data. Must be valid JSON.

function Script.cancelPost

Script.cancelPost(scheduleId: ID | null): boolean

Cancel a message previously scheduled with Script.post with a delay.

The post can only be canceled from the same room instance that sent it. The method returns true if the post was successfully canceled, or false if the scheduleId is either null, not sent by the script instance, or if the post was already sent.

Parameters

  • scheduleId (ID | null): Schedule ID returned by script.Post.

Returns

  • (boolean): True if the post was successfully canceled, otherwise false.

function Script.getChar

Script.getChar(charId: ID): Char | null

Gets info on an existing character.

To get character description or image info use Room.getChar instead.

Parameters

  • charId (ID): Character ID.

Returns


function Script.listen

Script.listen(addrs: Array<string> | null = null): void

Starts listening for messages and requests, sent with Script.post, Script.broadcast, and Script.request, from any of the given addr addresses. If an address is a non-instance room, it will also listen to posted messages from any instance of that room.

If no addr is provided, the script will listen to posts and requests from any source, including scripts and bots controlled by other players, and also listen for broadcasts by scripts in the same room.

Posts from the current script does not require listening. A script can always post to itself.

To get the address of a room script, use the roomscript command. For more info, type:

help roomscript

Parameters

  • addrs (Array<string> | null)

function Script.post

Script.post(addr: string, topic: string, data: string | null = null, delay: i64 = 0): ID | null

Posts a message to another script with the address addr. The receiving script will get the message through the onMessage entry point.

To get the address of a room script, use the roomscript command. For more info, type:

help roomscript

Parameters

  • addr (string): Address of target script. If addr is "#", it will be a post to the current script instance.
  • topic (string): Message topic. May be any kind of string.
  • data (string | null): Additional data. Must be valid JSON.
  • delay (i64): Delay in milliseconds.

Returns

  • (ID | null): Schedule ID or null if the message was posted without delay of if the receiving script was not listening.

function Script.request

Script.request(addr: string, topic: string, data: string | null = null): Response

Sends a request to another script with the address addr. The receiving script will get the request through the onRequest entry point. The requesting script will wait and block until a response is received, or a timeout occurs.

Errors will be returned as part of the response. The script should call Response.isError to check if an error was returned. In case of errors, calling Response.parseResult will cause the script to abort. Requests to self, or circular requests (A -> B -> A) will always return with an error.

To get the address of a room script, use the roomscript command. For more info, type:

help roomscript

Parameters

  • addr (string): Address of target script. If addr is "#", it will be a post to the current script instance.
  • topic (string): Message topic. May be any kind of string.
  • data (string | null): Additional data to be sent with the request. Must be valid JSON.

Returns


function Script.unlisten

Script.unlisten(addrs: Array<string> | null = null): void

Starts listening for posted messages from any of the given addr addresses. If an address is a non-instance room, it will also listen to posted messages from any instance of that room.

If no addr is provided, the script will listen to posts from any source.

To get the address of a room script, use the roomscript command. For more info, type:

help roomscript

Parameters

  • addrs (Array<string> | null)

Script classes

class Script.Char

Realm character.

class Script.Char properties

  • id (string): Character ID.
  • name (string): Character name.
  • surname (string): Character surname.
  • avatar (ID): Character avatar.
  • species (string): Character species.
  • gender (string): Character gender.
  • state (CharState): Character state.
  • idle (IdleLevel): Character idle status.
  • rp (RPState): Character RP state.

Store functions

function Store.deleteKey

Store.deleteKey<T>(key: T): void

Deletes a key and it's value from the store. If the key does not exist, this is a no-op.

Parameters

  • key (T): Stored key.

function Store.getBuffer

Store.getBuffer<T>(key: T): ArrayBuffer | null

Returns the stored ArrayBuffer value for the key, or null if the key does not exist.

Parameters

  • key (T): Stored key.

Returns

  • (ArrayBuffer | null)

function Store.getString

Store.getString<T>(key: T): string | null

Returns the stored string value for the key, or null if the key does not exist.

Parameters

  • key (T): Stored key.

Returns

  • (string | null)

function Store.readOnly

Store.readOnly(): void

Sets the database transaction to read-only during the script call, allowing multiple iterators to be open at the same time.

Must be called before using the store.


function Store.setBuffer

Store.setBuffer<T>(key: T, value: ArrayBuffer): void

Adds a key and an ArrayBuffer value to the store, or updates that key's value if it already exists.

Parameters

  • key (T): Stored key.
  • value (ArrayBuffer): Stored value.

function Store.setString

Store.setString<T>(key: T, value: string): void

Adds a key and a string value to the store, or updates that key's value if it already exists.

Parameters

  • key (T): Stored key.
  • value (string): Stored string value.

function Store.totalBytes

Store.totalBytes(): i64

Returns the total number of bytes used by the store for this script address.

Returns

  • (i64)

Store classes

class Store.Iterator

Iterator is an object that iterates over a storage.

new Store.Iterator()

Constructor of the Iterator instance.


method Store.Iterator.withPrefix

withPrefix<T>(prefix: T): Iterator

Sets a prefix to use for calls to seek, rewind, and isValid.

Must be called before using the iterator.

Parameters

  • prefix (T): Key prefix used in seek, rewind, and isValid.

Returns


method Store.Iterator.inReverse

inReverse(): Iterator

Sets direction of iteration to be in lexiographcially reversed order.

Must be called before using the iterator.

Returns


method Store.Iterator.next

next(): void

Advances the iterator by one. Always check isValid() after a next() to ensure have not reached the end of the iterator.


method Store.Iterator.seek

seek<T>(key: T): void

Seeks to the provided key if found. If not found, it would seek to the next smallest key greater than the provided key if iterating in the forward direction. Behavior would be reversed if iterating backwards.

Any iterator prefix passed to withPrefix() will be prepended to the key.

Parameters

  • key (T)

method Store.Iterator.rewind

rewind(): void

Rewinds the iterator cursor all the way back to first position, which would be the smallest key, or greatest key if inReverse() was called.

Any iterator prefix passed to withPrefix() will be used on rewind. The iterator is rewound by default.


method Store.Iterator.getKeyString

getKeyString(): string

Returns the key string of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns

  • (string)

method Store.Iterator.getKeyBuffer

getKeyBuffer(): ArrayBuffer

Returns the key ArrayBuffer of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns

  • (ArrayBuffer)

method Store.Iterator.getValueString

getValueString(): string

Returns the string value of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns

  • (string)

method Store.Iterator.getValueBuffer

getValueBuffer(): ArrayBuffer

Returns the ArrayBuffer value of the current key-value pair. It will abort if the cursor has reached the end of the iterator.

Returns

  • (ArrayBuffer)

method Store.Iterator.isValid

isValid(): boolean

Returns false when the cursor is at the end of the iterator.

Any iterator prefix passed to withPrefix() will be used as prefix.

Returns

  • (boolean)

method Store.Iterator.isValidForPrefix

isValidForPrefix<T>(prefix: T | null): boolean

Returns false when the cursor is at the end of the iterator, or when the current key is not prefixed by the specified prefix.

Any iterator prefix passed to withPrefix() will be prepended to the provided prefix.

Parameters

  • prefix (T | null)

Returns

  • (boolean)

method Store.Iterator.close

close(): void

Closes the iterator. Any further calls to the iterator will cause an error. May be called multiple times.