VBscript supports the functions JOIN() and SPLIT().
JOIN takes an array and a delimiter (such as ",") and returns a delimited string which can be crammed into a MUSHclient variable with little problem
SPLIT takes a string and a delimiter and chops the string apart wherever it finds the delimiter, returning an array.
You could easily do the following:
Quote:
Dim aArray
aArray=Array("Foo","Bar","Baz","Gleep")
World.SetVariable "ArrayTest",Join(aArray,":")
'ArrayTest now contains "Foo:Bar:Baz:Gleep"
'I don't have to use a colon. I normally use a comma,
'but all the commas makes my example harder to read.
'You could choose a space, a tilde, the string " and ",
'or whatever you want to use to separate your array
'elements. You don't have to rigidly stick to the
'example.
Later in your script, you can get your array back like so:
Quote:
Dim aArray,i
aArray=Split(World.GetVariable("ArrayTest"),":")
For i = lbound(aArray) to Ubound(aArray)
World.Note "element " & i & " contains " & aArray(i)
next
Using JOIN and SPLIT to turn your arrays into strings and back means you don't have to *simulate* using arrays. You really can use actual arrays. You simply use MUSHclient variables to store the contents, and load them into arrays when you want to work with them.
If you work with multidimensional arrays, you'll have to use JOIN and SPLIT inside loops or something, and you'll use a different delimiter for each dimension. A two-dimensional array rendered as a string might look like this:
foo1,bar1,baz1,gleep1:foo2,bar2,baz2,gleep2:foo3,bar3,baz3,gleep3
Split the string on : to get substrings. Split the substrings on , to get individual elements. Store the results in a two-dimensional array.
|