Need some help.

Posted by Sleaker on Thu 19 Sep 2002 01:57 AM — 6 posts, 24,172 views.

#0
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
Australia Forum Administrator #1
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.
#2
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.
#3
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.
#4
Ehh, that's alright, I just want to know how to make global variables then use them in different subs :D
Australia Forum Administrator #5
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.