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
➜ Need some help.
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Sleaker
(24 posts) Bio
|
Date
| Thu 19 Sep 2002 01:57 AM (UTC) |
Message
| k I'm trying to find out what this line does as a trigger.
^[A-Za-z *]*\[(.*)\](.*) x:(.*) y:(.*) z:(.*) r:(.*) b:(.*) s:(.*) h:(.*) S:(.*)
for some reason when I reference theparameter(9) it takes anything after the h: instead of stopping at the S:
and when I ask for theparameter(10) instead of displaying what's after the S: it displays the whole entire line..
Other than that all the other variables I am grabbing from this line are working correctly.
Here's the VB code I have using this, cut short cause it's long but relevant info is there..
Sub StoreContact(thename, theoutput, theparameter)
'Inputs: Contact information from a "contacts"
'Outputs: None
'Purpose: Stores contact data on targets for later manipulation.
' A damage record is generated at this point if the target doesn't have one
Dim strID, strName, strLoc1, strLoc2, strLoc3, strHead, strSpeed, strStatus, strRange
Dim strData, strStored, strConChan, strStoredData, tCallIt, strDamage
Dim strOldContactInfo, strConType
strID = Trim(theparameter(1))
strStored = World.getvariable("DesiredContact")
strConChan = World.getvariable("ContactChannel")
strName = Trim(theparameter(2))
strLoc1 = "%cbX:%cy " & Trim(theparameter(3))
strLoc2 = "%cbY:%cy " & Trim(theparameter(4))
strLoc3 = "%cbZ:%cy " & Trim(theparameter(5))
strRange = "%cbRange:%cy " & Trim(theparameter(6))
strHead = "%cbHead:%cy " & Trim(theparameter(9))
strSpeed = "%cbSpeed:%cy " & Trim(theparameter(8))
strStatus = "%cbStatus:%cy " & Trim(theparameter(10))
strConType = Left(strName, 1)
strName = Trim(Mid(strName, 2, Len(strName)))
If strName = "something" Then
strOldContactInfo = world.GetVariable("CONTACTDATA_" & strID)
If Len(strOldContactInfo) = 0 then
strData = "[" & strID & "] - %cm" & strName & " %cy-" & strLoc & " " & strRange & " " & strSpeed & " " & strHead & " " & strStatus
Else
strData = left(strOldContactInfo, InStr(1, strOldContactInfo, "- x:")-1) & "- " & strLoc & " " & strRange & " " & strSpeed & " " & strHead & " " & strStatus
End if
Else
strData = "[" & strID & "] - " & strName & " - " & strLoc1 & " " & strLoc2 & " " & strLoc3 & " " & strRange & " " & strSpeed & " " & strHead & " " & strStatus
End If | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 19 Sep 2002 02:42 AM (UTC) |
Message
| First, you may need to make your wildcards "less greedy" which means it only matches the minimum amount. To do this change:
(.*)
to
(.*?)
Second, MUSHclient allows a maximum of 9 wildcards, and the 10th is the "entire matching string" which is why you are getting that behaviour.
One approach would be to break down the line inside the trigger script. Another would be to make two triggers, one that matches on the first 9 variables, the other on the rest. To do this you need to tell the triggers to "not remember" some of the groups. A simple way is to simply omit the brackets, another way is to do this:
^[A-Za-z *]*\[(?:.*?)\](?:.*?) x:(?:.*?) y:(?:.*?) z:(?:.*?) r:(?:.*?) b:(?:.*?) s:(?:.*?) h:(?:.*?) S:(.*?)
This example tells the first nine brackets to be not counted as wildcards, so that whatever follows the S: will then be wildcard 1.
Of course, you need to mark both triggers as "keep evaluating" so they both get processed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Sleaker
(24 posts) Bio
|
Date
| Reply #2 on Thu 19 Sep 2002 02:51 AM (UTC) |
Message
| I see how that works, but how would I be able to make the variables Global so both Subs can use them? Do I put the Dim strBlah at the top outside of the Sub. Then just use them like I would normally? cause I'd have 3 Subs now instead of just 1. 2 for the Text evals and 1 to manipulate it. | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #3 on Thu 19 Sep 2002 03:19 AM (UTC) |
Message
| If you would like to use all 10 items from the regex, here's a function I created in VBScript to help me with triggers that required more than 9 items:
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 regEx = Nothing
Set Matches = Nothing
Set expand_regex = Match.SubMatches
Set Match = Nothing
Set strName = Nothing
Set strLine = Nothing
End Function
Brief explanation:
strName - Trigger name that contains the regex you want to match
strLine - The full line of data you originally matched on that you want to parse through the regex
Example parent routine:
Sub GetData(byVal strLine, byVal strName, byVal astrParam)
Dim astrLongParamList
Set astrLongParamList = expand_regex(strLine, strName)
' use data in astrLongParamList
Set astrLongParamList = Nothing
End Sub
As you can see, it pulls in the first 2 parameters originally sent to the trigger's subroutine to make it easiest to deal with. | Top |
|
Posted by
| Sleaker
(24 posts) Bio
|
Date
| Reply #4 on Thu 19 Sep 2002 03:26 AM (UTC) |
Message
| Ehh, that's alright, I just want to know how to make global variables then use them in different subs :D | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #5 on Thu 19 Sep 2002 05:27 AM (UTC) Amended on Thu 19 Sep 2002 05:28 AM (UTC) by Nick Gammon
|
Message
|
Quote:
I see how that works, but how would I be able to make the variables Global so both Subs can use them? Do I put the Dim strBlah at the top outside of the Sub. Then just use them like I would normally?
Yes, you can do that. eg.
dim a, b, c
sub nick
a = 5
end sub
sub test
b = 6
end sub
sub blah
c = a + b
end sub
I had forgotten about the regexp parsing available in VBscript, Vaejor is quite right that it is a good workaround for MUSHclient's 10-wildcard limitation. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
21,091 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top