I would like to introduce a new feature that I have been working on for MUSHclient, in time for comment before it becomes official. :)
There have been some recent posts here about maintaining "lists of things", with the added problem of adding or deleting from the list.
You can do that to a certain extent in VBscript with arrays (dim blah (10)), and also by using Split and Join, however that gets fiddly if you want to just add something to the middle, or remove something from the middle.
I thought it would be nice to leverage off the container management functions provided in STL (Standard Template Library) and offer some similar things for MUSHclient scripts.
This is based around what I will call an "array", with the new script functions being Arrayxxxxxx where "xxxxxx" is some array-based function.
Arrays have the following properties:
I'll work through an example here to show the idea. The examples show the script commands in VBscript, followed by the output from the output window in italics.
First, we'll create an array called "spells" and put some values (for mana) into it ...
Now let's focus on a particular spell, "dispel magic". We'll see if we know about that one ...
And what value is returned for it? ...
Let's export it into a comma-delimited list ...
And put the same thing into a variable for saving with the world file ...
What spells do we know (names only)? ...
Let's delete one (farsight) ...
How many spells do we now know? ...
There have been some recent posts here about maintaining "lists of things", with the added problem of adding or deleting from the list.
You can do that to a certain extent in VBscript with arrays (dim blah (10)), and also by using Split and Join, however that gets fiddly if you want to just add something to the middle, or remove something from the middle.
I thought it would be nice to leverage off the container management functions provided in STL (Standard Template Library) and offer some similar things for MUSHclient scripts.
This is based around what I will call an "array", with the new script functions being Arrayxxxxxx where "xxxxxx" is some array-based function.
Arrays have the following properties:
- You can have any number of arrays
- They are stored in memory only, one set of arrays per world, and another set per plugin
- By using ArrayImport and ArrayExport you can easily copy arrays into a single string, for loading/saving into variables (eg. MUSHclient variables)
- Each array has a unique name (eg. spells, friends, foes)
- Each array consists of any number of key/value pairs
- You can randomly insert into, or delete from an array
- You can list all available arrays (names of arrays)
- You can list all the keys in a particular array
- There is no restriction on array names, or key names, except that they cannot be empty
- Array names, key names, and values have leading/trailing spaces stripped before they are stored
- The array names, and key names, are automatically sorted into alphabetic order.
I'll work through an example here to show the idea. The examples show the script commands in VBscript, followed by the output from the output window in italics.
First, we'll create an array called "spells" and put some values (for mana) into it ...
ArrayCreate "spells"
ArraySet "spells", "dragonskin", "45"
ArraySet "spells", "dispel magic", "15"
ArraySet "spells", "farsight", "15"
ArraySet "spells", "galvanic whip", "30"
Now let's focus on a particular spell, "dispel magic". We'll see if we know about that one ...
s = "dispel magic"
Note "spell " & s & + " exists = " & ArrayKeyExists ("spells", s)
spell dispel magic exists = True
And what value is returned for it? ...
Note "mana required for " & s & " = " & ArrayGet ("spells", s)
mana required for dispel magic = 15
Let's export it into a comma-delimited list ...
Note ArrayExport ("spells", ",")
dispel magic,15,dragonskin,45,farsight,15,galvanic whip,30
And put the same thing into a variable for saving with the world file ...
SetVariable "spells", ArrayExport ("spells", ",")
What spells do we know (names only)? ...
Note ArrayExportKeys ("spells", ", ")
dispel magic, dragonskin, farsight, galvanic whip
Let's delete one (farsight) ...
ArrayDeleteKey "spells", "farsight"
How many spells do we now know? ...
Note ArraySize ("spells")
3