world.ArrayImport

MUSHclient script function (Method) — introduced in version 3.46

Imports values into an array from a single string

Prototype

long ArrayImport(BSTR Name, BSTR Values, BSTR Delimiter);

Data type meanings

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.

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.

Return value

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

Return code meanings

Related topic

Arrays

See also

FunctionDescription
ArrayExportExports values from an array into a single string
ArrayExportKeysExports keys from an array into a single string
ArrayGetGets the value of an array item
ArrayListKeysGets the list of all the keys in an array
ArraySetSets the value of an array item