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

MUSHclient scripting

Description of MUSHclient world function: world.SetVariable

Name SetVariable
Type Method
Summary Sets the value of a variable
Prototype long SetVariable(BSTR VariableName, BSTR Contents);

View list of data type meanings


Sets the contents of a variable. If the named variable already exists the contents are replaced. If the variable doesn't exist it is created. Variables are contained in the "world" configuration, and saved when the world is saved. You can use variables to "remember" data from one session of MUSHclient to the next.

* Rules for names

Names of triggers, aliases, timers and variables must follow these rules:

a. Start with a letter (A-Z)
b. Be followed by letters (A-Z), numbers (0-9) or the underscore character (_)

Please note that the following characters will not be handled correctly:

* The byte value hex 00 (otherwise known as 0x00 or null). This is used as a string terminator in MUSHclient, and attempts to imbed 0x00 values into variables will result in the variable being terminated at the 0x00 position.

* Carriage-return (hex 0D or 0x0D) and line-feeds (hex 0A or 0x0A). You can use these internally however you like, however when they are read from a plugin state file, or a MUSHclient world file, carriage returns are dropped, and line-feeds are converted to the sequence 0x0D 0x0A (carriage-return followed by linefeed). This is not normally a problem - because line breaks are usually stored as carriage-return/linefeed, and the reading process effectively will read them back in as that. However individual carriage-returns or linefeeds will not be read back in correctly.

If you are planning to use variables to store "binary" data - that is, data that can have all 256 possible character values, you are advised to convert them to base-64 encoded strings (using Base64Encode) when saving them, and conver them back (using Base64Decode) when loading them. Also be aware that only the Lua version of the base 64 encoding (utils.base64encode and utils.base64decode) will correctly handle the 0x00 value.

VBscript example
world.SetVariable "MyName", "Nick Gammon"
Jscript example
world.SetVariable("MyName", "Nick Gammon");
PerlScript example
$world->SetVariable("MyName", "Nick Gammon");
Python example
world.SetVariable("MyName", "Nick Gammon")
Lua example
SetVariable ("MyName", "Nick Gammon")
Returns eInvalidObjectLabel: The variable name is not valid
eOK: The variable contents were set

View list of return code meanings

See also ...

Function Description
GetVariable Gets the contents of a variable
GetVariableList Gets the list of variables

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]