ArrayImport
Script function

world.ArrayImport

DOC_scripting Read about scripting

Type

Method

Summary

Imports values into an array from a single string

Prototype

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

DOC_data_types View list of 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


DOC_errors View list of return code meanings


See Also ...

Topics

DOC_Arrays Arrays
DOC_plugins Plugins
DOC_scripting Scripting
DOC_variables Variables

Functions

FNC_ArrayClear ArrayClear (Clears an array)
FNC_ArrayCount ArrayCount (Returns the number of arrays)
FNC_ArrayCreate ArrayCreate (Creates an array)
FNC_ArrayDelete ArrayDelete (Deletes an array)
FNC_ArrayDeleteKey ArrayDeleteKey (Deletes a key/value pair from an array)
FNC_ArrayExists ArrayExists (Tests to see if the specified array exists)
FNC_ArrayExport ArrayExport (Exports values from an array into a single string)
FNC_ArrayExportKeys ArrayExportKeys (Exports keys from an array into a single string)
FNC_ArrayGet ArrayGet (Gets the value of an array item)
FNC_ArrayGetFirstKey ArrayGetFirstKey (Gets the key of the first element in the array (if any))
FNC_ArrayGetLastKey ArrayGetLastKey (Gets the key of the last element in the array (if any))
FNC_ArrayKeyExists ArrayKeyExists (Tests to see if the specified array key exists)
FNC_ArrayListAll ArrayListAll (Gets the list of arrays)
FNC_ArrayListKeys ArrayListKeys (Gets the list of all the keys in an array)
FNC_ArrayListValues ArrayListValues (Gets the list of all the values in an array)
FNC_ArraySet ArraySet (Sets the value of an array item)
FNC_ArraySize ArraySize (Returns the number of elements in a specified array)

(Help topic: function=ArrayImport)

DOC_contents Documentation contents page