It is often very useful to be able to match a trigger on more than 1 line. Although Mushclient lacks this ability, it can be mimicked with scripting. I remember another post on this matter before, what this one aims at is to provide a more or less generalized way of simulating multiline triggers in Mushclient using vbs scripting. I haven't done too much testing on this, and I can see quite a few messy points in it, but it seems to work and to provide a way of matching several lines of text. That's all I wanted from it. Any input on it is very much welcome, as I'd love to have some simple and reliable function I could call to quickly check up on a few lines of output.
This particular function accepts 2 arguments: first is a number of lines you want to look back (actually that's minus 1 - if you want to match 2 lines prior to the most recent one you need to send 1 to the function as its' first argument, that's screwed up but simplifies things inside the function somewhat), second is an array of trigger names (read below). Obviously, trigger names must come in a reverse order - first the one for the most recent line - 1, then for the most recent line - 2, etc.
The function uses a dictionary in which the keys are used as "trigger labels" and items as "trigger match text". That's done to achieve the closest possible resemblance to how it works in Mushclient. If you are only using the function, then you don't need to bother figuring out how exactly this dictionary works, you only need to know what key-item pairs are in it. For an example of how those pairs are added look in the beginning of the script below.
Once again, I'd appreciate any input on any parts of this or the whole thing. Thanks in advance
option explicit
'This is a dictionary of "internal triggers" - keys are used as trigger names
'and items are trigger match strings in regexp
'
dim triggsDict
set triggsDict = CreateObject("Scripting.Dictionary")
triggsDict.Add "raze", "^(?:\d+h, \d+m \D*-|)\D+ razes your aura of weapons rebounding\."
triggsDict.Add "slash", "^(?:\d+h, \d+m \D*-|)\D+ slashes into you with a steel shortsword\."
'This is the function. It can return one of 3 values: 1, 2, and 3. Since I didn't feel like
'messing with exceptions, return value of 3 means that you've supplied an invalid
'trigger name (a triggsDict key), and that's as far as error-checking goes in this one.
'Value of 1 means that all the triggers have successfuly matched, 2 - one or more
'didn't match. I only tested this with 2 preceding triggers and wasn't very thorough
'with it either, so you might want to do your own testing before putting this to use
'anywhere.
'
function LookBack (numberOfLines, triggers)
dim i, regEx, line, lineCount, lineText, Match, Matches, result, trigNum
Redim result(numberOfLines)
for i = 0 to ubound(result)
result(i) = 0
next
lineCount = world.GetLinesInBufferCount
trigNum = 0
for i = 0 to ubound(triggers)
if not triggsDict.Exists(triggers(i)) then
world.Note "Internal trigger not found: " & triggers(i) & ". Exiting function LookBack."
LookBack = 3
exit function
end if
next
for i = 0 to numberOfLines
if i then
if result(i - 1) = 0 then
LookBack = 2
exit function
end if
line = line - 1
else
line = lineCount - 1
end if
do while world.GetLineInfo (line, 4)
line = line - 1
loop
set regEx = new RegExp
regEx.Pattern = triggsDict.Item(triggers(trigNum))
trigNum = trigNum + 1
lineText = world.GetLineInfo(line, 1)
set Matches = regEx.Execute(lineText)
for each Match in Matches
result(i) = 1
next
world.note result(i)
next
for i = 0 to ubound(result)
if result(i) <> 1 then
LookBack = 2
end if
next
LookBack = 1
end function
'This is a test sub I used
'
sub TestTriggs(name, output, wildcs)
dim trigs
trigs = Array("slash", "raze")
if LookBack(1, trigs) = 1 then
world.Note "found"
else
world.Note "not found"
end if
end sub
|