[Home] [Downloads] [Search] [Help/forum]

MUSHclient scripting

Description of MUSHclient world function: world.SaveState

Name SaveState
Type Method
Summary Saves the state of the current plugin
Prototype long SaveState();

View list of data type meanings


This causes the current plugin to save its state (ie. its variables) to its "state" file. You might call this in a timer every couple of minutes to ensure that variables are saved in the event of a program or computer crash.

If a plugin has:


in its plugin configuration (header), then its state is saved automatically as described below.

Plugins automatically save their state when they are closed (ie. when they are uninstalled, or when the world closes), and when the world file is saved. However if the world does not close for days then you may want to arrange for the plugin to save its state more often, particularly if the variables that the plugin is using are valuable.

The plugins by default save their state to a directory called "state" which is a subdirectory of the nominated "world plugins directory". If no such directory exists, then the plugin cannot save its state. The "save state" directory can be found by doing GetInfo (85).

There is a state file for each world/plugin combination.

The file name will look like this:


This is:

(world ID)-(plugin ID)-state.xml

Each world should have a unique ID, and each plugin should have a unique ID, thus each world's plugin's state should have a unique file name.

Plugins are also forced to save their state when the main world file is saved (ie. world.Save is called, or you save the world file from the File menu).

If the plugin has an OnPluginSaveState function this is called before the state is saved - this lets the plugin serialize its script variables - that is, convert from script internal variables to MUSHclient variables.

If a plugin is not executing (that is, if this is called from outside a plugin execution) then no state can be saved and an error code is returned.

Prior to version 4.56 a plugin could not save its state by calling this function unless save_state was set as "y" in the plugin header.

VBscript example
Jscript example
world.SaveState ();
PerlScript example
$world->SaveState ();
Python example
Lua example
SaveState ()
Lua notes
See the forum thread http://www.gammon.com.au/forum/?id=4960 for suggestions about how to serialize Lua tables into a variable. This has example OnPluginSaveState functions.
Returns eNotAPlugin: Script is not currently executing inside a plugin.
ePluginCouldNotSaveState: The plugin could not save its state (eg. no "state" directory, disk full, not permitted)
eOK: Plugin saved its state OK.

View list of return code meanings

See also ...

Function Description
CallPlugin Calls a routine in a plugin
EnablePlugin Enables or disables the specified plugin
GetPluginInfo Gets details about a specified plugin
PluginSupports Checks if a plugin supports a particular routine

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.

Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes

Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes

View all functions


Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]