Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ wildcards
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Simon
Sweden (39 posts) Bio
|
Date
| Fri 10 Jan 2003 11:49 PM (UTC) |
Message
| is the max usable nr of wildcards 9? if not, how do I access the ones 9+? since 10 is the entire trigger? |
- "Where do you live, Simon?"
- "I live in the sick and wounded, doc."
Session 9 | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #1 on Sat 11 Jan 2003 01:00 PM (UTC) |
Message
| 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:
^(?:> )*(\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. |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| Simon
Sweden (39 posts) Bio
|
Date
| Reply #2 on Sun 12 Jan 2003 01:16 PM (UTC) |
Message
| But the problem is that there are 11 variables I want out from a one-line trigger. It's my hp bar :) |
- "Where do you live, Simon?"
- "I live in the sick and wounded, doc."
Session 9 | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #3 on Sun 12 Jan 2003 04:29 PM (UTC) |
Message
| Core function:
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
| Top |
|
Posted by
| Simon
Sweden (39 posts) Bio
|
Date
| Reply #4 on Sun 12 Jan 2003 04:34 PM (UTC) |
Message
| 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 :) |
- "Where do you live, Simon?"
- "I live in the sick and wounded, doc."
Session 9 | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #5 on Sun 12 Jan 2003 05:19 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Simon
Sweden (39 posts) Bio
|
Date
| Reply #6 on Sun 12 Jan 2003 09:51 PM (UTC) |
Message
| 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 |
- "Where do you live, Simon?"
- "I live in the sick and wounded, doc."
Session 9 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #7 on Sun 12 Jan 2003 11:08 PM (UTC) |
Message
| There is a MUSHclient "replace" function - use that to replace commas with nothing, then do a CInt on the result. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Simon
Sweden (39 posts) Bio
|
Date
| Reply #8 on Mon 13 Jan 2003 11:58 AM (UTC) |
Message
| That solved it :) Thanks a bunch! :) |
- "Where do you live, Simon?"
- "I live in the sick and wounded, doc."
Session 9 | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
31,053 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top