Alright, here I am just working on a bit of a bot, yes i know in some muds they are illegal, etc.. but this mud, as long as you can respond to certain 'tests', then its alright, even if you are using scripts... here we go..
One thing I can't figure out is.. how would I go about doing a "list", I thought about using arrays, but lets say, like in zmud, or anything, I always did something like... When i ran into a monster, I added it to the list, when that monster died, I removed it from the list (always going by the first mob)... well lets give an example..
I add these to the list:
orc, troll, dragon, cat, chicken, dog
ok, the first being "orc", so I kill orc, once i see:
* is dead!
I delete the first item in the list, and then go on to the second one, etc... until the list is empty, they I can go on to the next room or whatever or loot all the corpses...etc.. now how would I work with this in VBScript using i guess... arrays? (Just need some functions of some sort, or a bit of a "push") Thanks for the help again!
a friend of mine, just said something about 'collections' but out of all the stuff I've been reading, I can't find anything about that.. maybe he is right, but *shrugs* still nothing on the subject...
Collections are the most mysterious area of Vbscript, if you ask me. I think they are somehow hardcoded into the script host and can't be tempered with directly, or at least that's what the docs seem to imply. The closest thing to lists in Vbscript are dynamic arrays, but you can't use those for your purposes either, since you can't redimension an array by popping an index in the middle. What I'd do is use string operations - Left(), Right(), Instr(), etc. - and following are a couple of functions that might come usefull. Actually I'd move to Python or something that supports lists, but that's a different story :) Anyways, here it goes...
'Appends newItem to the end of strList, using the 'delim' delimiter
'doesn't perform any checks, returns the new list
'
function ListAppend(strList, newItem, delim)
ListAppend = strList & delim & newItem
end function
'Adds newItem to the end of the list, using the 'delim' delimiter, only if newItem
'isn't already in the list. Returns the new list if the item was added, original list
'if the item was already present
'
function ListAdd(strList, newItem, delim)
if instr(strList, newItem) then
ListAdd = strList
else
strList = strList & delim & newItem
ListAdd = strList
end if
end function
'Removes the removeItem from the list if it is present there,
'returns the new list if the item was removed, original list if the item wasn't
'found.
'
function ListRemove(strList, removeItem, delim)
dim startPos, endPos, resultList
startPos = instr(strList, removeItem)
if startPos then
endPos = instr(startPos, strList, delim)
if endPos then
resultList = Left(strList, startPos - 1) + Right(strList, len(strList) - endPos)
ListRemove = resultList
else
resultList = Left(strList, startPos - 1)
ListRemove = resultList
end if
else
ListRemove = strList
end if
end function
'Example of usage:
dim mobList
mobList = "orc_dragon_cat"
sub TestLists(name, output, wildcs)
'Add "dog" to the mobList
mobList = ListAdd(mobList, "dog", "_")
world.Note mobList
'Remove "cat" from the mobList
mobList = ListRemove(mobList, "cat", "_")
world.Note mobList
'Add "cat" back to the list
mobList = ListAdd(mobList, "cat", "_")
world.Note mobList
'Remove "urchin" from the list, it's not there so the list isn't changed
mobList = ListRemove(mobList, "urchin", "_")
world.Note mobList
'Appends another "cat" to the end of the list
mobList = ListAppend(mobList, "cat", "_")
world.Note mobList
end sub
These took about 15 minutes to write, and although I tested them (using the TestLists sub above) there might be some quirks left.
A quick way of managing things like that would be to store them in a single variable, separated by commas, and use Split to get at the individual items.
Here is an example you can type into the Immediate window to get the idea ...
v = "orc, troll, dragon, cat, chicken, dog"
mylist = split (v, ",")
for each m in mylist
Note trim (m)
next
Output
orc
troll
dragon
cat
chicken
dog
Now inside the for loop you could test to see if a word was there (eg. "orc") and if so you know he is a known mob, if not you could add him.
eg.
v = v & ", gorilla"
Another approach is to use Join to turn an array into a variable. For instance, adding onto the earlier example:
k = join (mylist, ",")
Note k
Output
orc, troll, dragon, cat, chicken, dog
Ok cool, Thanks both of you very much!! Alright, another question... sort of on the same subject I suppose, is there a way to create custom "windows"? Sort of like other mud clients, where you can have things displayed in there, or buttons or anything like that? thanks for the help again!
You can if you use VB and the COM interface. I did an example a little while back of a plugin that showed HP, Mana, Movement in three gauges in a separate window.
If you have access to VB (the full version) anything is possible.
*shakes his fist* You are trying to make me learn VB, I think everyone is plotting to make me learn vb... You mean mean... semi-mean people... *hugs you all* i love you bastards...