Overview
TheScript class is the foundation of Lich’s script execution system. It manages script lifecycles, handles script-to-script communication, and provides methods for starting, stopping, and monitoring running scripts.
All scripts run in isolated threads with their own execution context, but can communicate through shared buffers and the global script registry.
Class Methods
Script.start
Starts a new script and returns immediately.Name of the script to start (without file extension)
Arguments to pass to the script
Optional configuration hash
:quiet- Suppress startup messages:force- Force start even if already running:args- Alternative way to pass arguments
Returns the Script object if successful, nil if the script couldn’t be started
Script.run
Starts a script and waits for it to complete before returning.Name of the script to run
Arguments to pass to the script
Script.kill
Terminates a running script.Name of the script to kill (case-insensitive regex match)
Returns true if script was found and killed, false otherwise
Script.running?
Checks if a script is currently running.Name of the script to check
Returns true if the script is running
Script.pause / Script.unpause
Pauses or resumes a running script.Name of script to pause/unpause. If omitted, pauses the current script.
Returns true/false for named scripts, or the Script object when pausing self
Script.paused?
Checks if a script is paused.Name of the script to check
Returns true if paused, false if running, nil if not found
Script.list
Returns all running scripts (including hidden ones).Array of all Script objects currently running
Script.running
Returns visible running scripts (excludes hidden scripts).Array of visible Script objects
Script.hidden
Returns only hidden scripts.Array of hidden Script objects
Script.current
Gets the currently executing script object.The Script object for the calling script, or nil if called outside a script
Script.exists?
Checks if a script file exists in the script directory.Name of the script to look for
Returns true if the script file exists
Script.version
Retrieve script version from header comments.Name of the script
If provided, returns true/false if script version meets requirement
Version object, or boolean if comparing versions
Script.at_exit
Registers a block to run when the script exits.Script.log
Writes a message to the script’s log file in the logs directory.Message to write to the log
Script.db
Opens a SQLite database for the current script.Database connection object for the script
Script.open_file
Opens a data file specific to the current script.File extension (e.g., ‘txt’, ‘csv’)
File mode (‘r’, ‘w’, ‘a’, etc.). Defaults to ‘r’
File handle for the script’s data file
Instance Methods
name
The script’s name (without path or extension).vars
Array of command-line arguments passed to the script.pause / unpause
Pauses or resumes the current script.paused?
Checks if the script is paused.Returns true if the script is paused
kill
Terminates the script.exit / exit!
Exits the script.exit! skips at_exit handlers.
Properties
quiet
Suppresses script start/stop messages.hidden
Hides script fromScript.running (but shows in Script.list).
want_downstream
Controls whether script receives game output in its buffer.want_downstream_xml
Controls whether script receives raw XML game output.ExecScript
ExecScript is a lightweight script type for one-off code execution.ExecScript.start
Executes Ruby code as a script.Ruby code to execute
Options hash (
:quiet, :name)