Skip to content

Scripted Commands

Jeremy Harton edited this page Apr 28, 2019 · 1 revision

Overview

Scripted commands are created by wrapping scripts in a ScriptedCommand object which, as a subclass of Command, can be placed in the command map like any other command (maps String -> Command, where the string is the use-name and the object contains the code to be executed). However executing a ScriptedCommand invokes the script interpreter with the internal script code plus any parameters/arguments passed.

Example

A scripted command can be written as follows:

String description = "This command gets the database reference num, or dbref, of the named object";
String script = "{dbref:{&arg}}";

final ScriptedCommand sc = new ScriptedCommand(description, script);

As the "script" is a one line string to be evaluated by the interpreter, it could theoretically by stored in a file and loaded into an object when you want it. The example above could be used in the code as follows:

sc.execute("something", client);

As far as the user is concerned, and the output seen, this is functionally equivalent to:

@pgm {dbref:something}

Clone this wiki locally