is the max usable nr of wildcards 9? if not, how do I access the ones 9+? since 10 is the entire trigger?
wildcards
Posted by Simon on Fri 10 Jan 2003 11:49 PM — 9 posts, 38,976 views.
There are other forum postings on this, somewhere.
Basically, you use a series of regular expression triggers. In your MUSHclient directory, there is a text file that explains all the syntax for regular expressions.
What it comes down to, is using ?: as a qualifier, indicating that you wish to match a line with a wildcard, but NOT return it as a result.
For example:
This would match on the following lines:
For each match, the name of the person would always be wildcard 1. The lines which have a prompt before them (A single "> ") are still matched, however that element is NOT returned as a wildcard.
"his/her" are also elements that can vary, but again, are NOT returned as a wildcard.
Basically, you use a series of regular expression triggers. In your MUSHclient directory, there is a text file that explains all the syntax for regular expressions.
What it comes down to, is using ?: as a qualifier, indicating that you wish to match a line with a wildcard, but NOT return it as a result.
For example:
^(?:> )*(\w*) lets (?:his|her) healing powers flow through the world\.$
This would match on the following lines:
Fyxen lets her healing powers flow through the world.
> Fyxen lets her healing powers flow through the world.
Eejit lets his healing powers flow through the world.
> Eejit lets his healing powers flow through the world.
For each match, the name of the person would always be wildcard 1. The lines which have a prompt before them (A single "> ") are still matched, however that element is NOT returned as a wildcard.
"his/her" are also elements that can vary, but again, are NOT returned as a wildcard.
But the problem is that there are 11 variables I want out from a one-line trigger. It's my hp bar :)
Core function:
Usage:
As you can see, you pass through the name of the trigger and the line that it captured(the first and second parameters normally passed to the Sub, respectively). It will use this information to pull the actually trigger's regular expression, rematch the regular expression using VBScript's internal regular expresion matching and return the requested data in an array.
I've only used it up to about 15 items, so I'm not positive what the upper limit is. It should be high enough for normal use though. Just remember that using this functionality, you have to start your array on 0. MushClient starts on 1, so it is easy to get them mixed up sometimes.
Useful links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsobjregexp.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriregularexpressionsobjectpropmeth.asp
Function expand_regex(ByVal strName, ByVal strLine)
Dim regEx, Matches, Match
Set regEx = New RegExp
regEx.Pattern = world.GetTriggerInfo(strName, 1)
Set Matches = regEx.Execute(strLine)
Set Match = Matches(0)
Set expand_regex = Match.SubMatches
Set regEx = Nothing
Set Matches = Nothing
Set Match = Nothing
Set strName = Nothing
Set strLine = Nothing
End Function
Usage:
Dim hp_hp
Dim hp_hp_max
Dim hp_sp
Dim hp_sp_max
Dim hp_hp_perc
Dim hp_sp_perc
Sub hp_bar1_1(ByVal strName, ByVal strLine, ByVal astrParam())
Dim astrData
Set astrData = expand_regex(strName, strLine)
hp_hp = CInt(astrData(0))
hp_hp_max = CInt(astrData(1))
hp_sp = CInt(astrData(2))
hp_sp_max = CInt(astrData(3))
'... etc ...
hp_hp_perc = (hp_hp * 100) / hp_hp_max
hp_sp_perc = (hp_sp * 100) / hp_sp_max
Set astrData = Nothing
Set strName = Nothing
Set strLine = Nothing
Erase astrParam
Set astrParam = Nothing
End Sub
As you can see, you pass through the name of the trigger and the line that it captured(the first and second parameters normally passed to the Sub, respectively). It will use this information to pull the actually trigger's regular expression, rematch the regular expression using VBScript's internal regular expresion matching and return the requested data in an array.
I've only used it up to about 15 items, so I'm not positive what the upper limit is. It should be high enough for normal use though. Just remember that using this functionality, you have to start your array on 0. MushClient starts on 1, so it is easy to get them mixed up sometimes.
Useful links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsobjregexp.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriregularexpressionsobjectpropmeth.asp
Cool thanks :) However, I ran into another problem in another trigger. Say that I have a string dim containing 123,456,789 and I want to strip it from all the ,'s and make it into an int dim? the thing is that it might also be like 234,543 so the nr. commas changes :)
A regular expression of
([0-9,]+)
should capture it.
I'm pretty sure a CInt(), CLng(), CSng(), or CDbl() will appropriately remove commas and return the number you're expecting.
Integer variable types in VB have an upper limit of 32,767(2^15-1).
Long variable types in VB have an upper limit of 2,147,483,647(2^31-1).
You'll probably need to use a CLng() for the numbers you've specified so far.
([0-9,]+)
should capture it.
I'm pretty sure a CInt(), CLng(), CSng(), or CDbl() will appropriately remove commas and return the number you're expecting.
Integer variable types in VB have an upper limit of 32,767(2^15-1).
Long variable types in VB have an upper limit of 2,147,483,647(2^31-1).
You'll probably need to use a CLng() for the numbers you've specified so far.
Hmm I tried but didn't get anywhere :( just got tons of errors. Since we are on the same mud I'll give you a quick explanation of what I want to do:
every time I kill something I do: xp, divvy, xp. to see how much xp I gained from the kill. So the information I want is:
Trigger on:
You have 1,206,794 total xp, with 93,206 to next level and 256,794 to spend.
(easy)
and then I want to take the first value from that trigger (wildcard 1) and subtract that with world.getvariable("experience"). Once that is done and printed, I want to world.setvariable "experience", wildcard 1
I can't get it working :( CDbl only gave me error messages :| ... ( used it as CDbl (world.getvariable..... etc
every time I kill something I do: xp, divvy, xp. to see how much xp I gained from the kill. So the information I want is:
Trigger on:
You have 1,206,794 total xp, with 93,206 to next level and 256,794 to spend.
(easy)
and then I want to take the first value from that trigger (wildcard 1) and subtract that with world.getvariable("experience"). Once that is done and printed, I want to world.setvariable "experience", wildcard 1
I can't get it working :( CDbl only gave me error messages :| ... ( used it as CDbl (world.getvariable..... etc
There is a MUSHclient "replace" function - use that to replace commas with nothing, then do a CInt on the result.
That solved it :) Thanks a bunch! :)