OK, thanks everyone. Starting from the top, and after a good night's sleep, I can think a bit more clearly ...
Quote:
Shadowfyr
*VBScript*>
sort - not available.
add - not available.
delete - not available.
...
Whether it is really useful or an improvement over anything other that what VBScript does is more of an issue.
I think this is the nub of it. Let's assume if you are writing a plugin that you want it to be useable on most people's PCs, that means basically VBscript or Jscript, because the other languages are an optional download.
I'm not sure whether Jscript supports keyed arrays, VB certainly doesn't (seem to).
I am using the word "array" loosely here. It is really a variant of a "map" in STL terminology, however I thought that using the word "map" would be confusing in a MUD client, as people associate maps with automappers and such.
I got the idea from PHP (which this web site's dynamic content is written in), where you can have arrays with alpha indexes, like this:
person ['nick'] = 42;
or
person [2] = 55;
As Ksilyan says, it is really an associative array.
This is much more powerful than simple VB arrays, which are really "vectors" in the STL sense.
However based on the comments "it can't create simple non-keyed arrays from what I can see" I will make a change I was thinking of anyway, and that is to modify the sorting/matching behaviour.
What I have in mind is this:
- Entries are keyed by an alpha key
- The key can be a number (eg. "100")
- If the key is a simple number, with or without sign, they will be sorted into numeric sequence
What this means is that you can easily treat the arrays as simple numeric arrays, without worrying about whether a sequence like 1, 11, 2 sorts as 1, 2, 11, or 1, 11, 2.
Straight "alpha" keys *would* sort as 1, 11, 2 as "11" is lower in the sort sequence than "2". This would make numeric keys fiddly to use, as you would have to put in leading zeroes.
That way, if you want a simple sequence of things, you just supply numeric keys (effectively creating a sparse vector), like this:
ArraySet "v", "1", "first entry"
ArraySet "v", "2", "second entry"
ArraySet "v", "40", "fortieth entry"
ArraySet "v", "100", "100th entry"
ArraySet "v", "-1", "this will now be first"
By "sparse" I mean you can index in with numbers, but not every position will necessarily be taken.
By choosing suitable key numbers you could implement a stack or a queue as well.
Quote:
Especially since your method to use more than one dimension is probably slower than using the script languages version.
I don't think speed is the major issue. I am thinking of things like an alias that might get information about a spell. Doing a keyed lookup is probably faster anyway than a linear search through variables or a language-dependent array anyway.
Having said that, the keyed lookup *would* be faster if you had a lot of them, because you could find (say) a spell out of a thousand by a simple lookup, whereas if you maintain a list, you may have to search through 999 of them to find it.
Quote:
Poromenos
NONONO please don't mess with the data... What if you want to store formatted output?
Yes I think you are right. If you want to get rid of the spaces you always can, but you can't put them back if they are gone.
I think I will also change it so it doesn't matter if the delimiter is in the data, I can see that as trouble waiting to happen.
I think something like the way mySQL exports its database as text files...
Say the delimiter is a comma, and you have data "fish,chips", it could be exported as:
food,fish\,chips
Then, of course, the \ symbol has to be exported as \\.
|