Search FAQ

MUSHclient scripting

Description of MUSHclient world function: world.ArrayImport


Name ArrayImport
Type Method
Summary Imports values into an array from a single string
Prototype long ArrayImport(BSTR Name, BSTR Values, BSTR Delimiter);
Description

Imports key/value pairs into the nominated array.

They keys and values must be separated by the specified delimiter, for example:

dispel magic,15,dragonskin,45,farsight,15,galvanic whip,30

The first word is the key (eg. dispel magic) the second word is the value (eg. 15) and so on, until the list of keys/values is exhausted.

It is an error if the number of keys/values is not even (that is, there should be one value for each key).

The list may be the empty string, in which case nothing is imported.

You may import on top of an existing array (ie. add to it). The new values are slotted in with the existing values. If the new values have the same key as existing values the existing values are overwritten. The return value from this function tells you if this happens.

You specify the delimiter (eg. a comma) so that you can use different delimiters if you want to. If you want to use the delimiter inside the key or value data, then you must precede it (escape it) with a backslash. Also, if you want to have backslashes in the keys or values, use a double-backslash.


Note: Available in version 3.46 onwards.


VBscript example
ArrayImport "spells", "dispel magic,15,dragonskin,45,galvanic whip,30", ","
Lua example
ArrayImport ("spells", "dispel magic,15,dragonskin,45,galvanic whip,30", ",")
Lua notes
The delimiter is optional, and defaults to the "," character.

As an optional extension you can supply a Lua table as the second argument, 
instead of a delimited string. (In this case there is no third argument).

eg.

t = {
    ['dispel magic'] = 15,
    dragonskin = 45,
    ['galvanic whip'] = 30
    }

ArrayImport ("spells", t)

This effectively lets you import into Lua tables with ArrayImport, and then
export later on with ArrayList.
Returns eBadArrayName: Name cannot be empty
eArrayDoesNotExist: Array does not exist
eArrayNotEvenNumberOfValues: There is not an even number of keys/values
eImportedWithDuplicates: Imported successfully, however there were duplicates which were overwritten
eCannotImport: The data to be imported contains the "escaped delimiter" sequence, and there is no unused character (eg. hex 01) to temporarily convert it to internally for importing purposes.

eOK: Imported OK
Introduced in version 3.46

See also ...

Function Description
ArrayExport Exports values from an array into a single string
ArrayExportKeys Exports keys from an array into a single string
ArrayGet Gets the value of an array item
ArrayListKeys Gets the list of all the keys in an array
ArraySet Sets the value of an array item

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

[Back]

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