Pretty simple actually. There are however some VBscript complications. The first problem is that normal arrays are not permanent. If you need to store the list when you close mushclient, things get *way* more complicated. This brings us to the second problem, I really don't get why, but to make something like zMud uses you could use 'join' and 'split', however arrays generated using 'split' are different in some obscure way from those created using normal methods. You can't split a string into an existing array, even if the array is created using 'name()' or 'redim name', both of which are *supposed* to produce dynamic arrays that can change sizes. Worse, arrays produced by 'split' are a fixed size, so also can't be resized to add or delete new items.
Anyway the normal method would be:
'Placing this *outside* of any subs makes it global to the entire script file.
' NOTE: varaibles used *in* triggers and aliases using 'send to script' are
' also automatically global, so it is very important to use completely unique
' names that can't conflict with values other aliases or your main script expect
' to remain the same.
redim MilkVialList
sub milking_vialadd (name, output, wilds)
ub = ubound(MilkVialList)
redim MilkVialList(ub + 1)
MilkVialList(ub + 1) = wilds(1)
end sub
The way to do it by using mushclient variables:
sub milking_vialadd (name, output, wilds)
MVL = getvariable("MilkVialList")
MVL = MVL + "," & wilds(1)
setvariable "MilkVialList", MVL
end sub
The real problem is when you try to 'remove' an item. In the case of the array, you can delete the last item in the list easy by simply doing:
ub = ubound(MilkVialList)
if ub > 0 then
redim MilkVialList(ub - 1)
end if
However, the get/set type requires either: 1) 'split'ing it into an array and then copying all but the last item into a new array, then 'join'ing that into the new string. or 2) using 'InStrRev' to find the last ',' and then a 'left' command to grab everything up to the character before that ','. If you have to remove an item from the middle of the list.... Then the problem grows exponentially, since there is no simple way to collapse an array and remove a single value from the middle of it. They should have made arrays in VBScript as collections instead, since then they would have supported the .sort, .add and .remove functions.
JavaScript however does treat them like collections and has the ability to use those functions directly with the array. However, Java is missing some other features that imho are used a lot more often. Either way you end up having to build your own scripts to make up for the stuff they didn't bother to include in the language. :( |