Regular Exp Trigger problem

Posted by David Berthiaume on Mon 30 Jan 2006 04:12 AM — 18 posts, 71,572 views.

#0
Right then. I've been having a go at this for some time now. I've exhausted everything that I can think of on how to do this.

My prompt changes at various times, depending on what I'm doing.
If I'm just hanging around it looks like this:
<100%> / <8,291/8,291>
If I'm in combat it looks like this:
<98%> / <7,056/7,895> vs. <232>
When I gain power level it looks like this:
<100%> / <7,450/7,895> +197 Max Powerlevel
Now then. The problem I'm having is I want to set a trigger to constantly monitor my max power level. I need it to keep track during combat, and during non combat periods. Sounds simple right? Well, I wish it were. Here is my trigger, followed by what I see on the screen(I'm using send to output to check the wildcards)
<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^(^\&lt;(.*)\%\&gt; \/ \&lt;(.*)\/(.*)\&gt;$|^\&lt;(.*)\%\&gt; \/ \&lt;(.*)/(.*)\&gt; vs. \&lt;(.*)\&gt;$)$"
   regexp="y"
   repeat="y"
   send_to="2"
  >
  <send>%1
%2
%3
%4</send>
  </trigger>
</triggers>
My output looks like this:
<100%> / <8,774/8,774> vs. <4,397>
<100%> / <8,774/8,774> vs. <4,397>
100
8,774
8,774> vs. <4,397
That was not exactly what I was looking for.

The first line is the actual prompt, the second is the whole line as a wild card, the third is the 2nd wild card, the fourth is the 3rd wildcard, but the fourth line keeps screwing up. I can't figure out how to get it to ignore that vs. part.

I know the trigger is working properly. When not in combat I get:
<100%> / <9,212/9,212>
<100%> / <9,212/9,212>
100
9,212
9,212
Which is exactly what I'm supposed to be getting. it's matching on the two different prompt lines. The problem is It's not breaking up the wildcards in the combat prompt properly.
Amended on Mon 30 Jan 2006 04:16 AM by David Berthiaume
#1
This trigger works fine though:
<triggers>
  <trigger
   custom_colour="2"
   match="^\&lt;(.*)\%\&gt; \/ \&lt;(.*)/(.*)\&gt; vs. \&lt;(.*)\&gt;$"
   regexp="y"
   repeat="y"
   send_to="2"
  >
  <send>%1
%2
%3
%4
%5
%6
%7</send>
  </trigger>
</triggers>
#2
I solved the problem, just not the way I wanted too, but I'm not gonna argue with results.

I have 2 different triggers. They both work, they both give me the information that I want.
Australia Forum Administrator #3
I spent a bit of time looking at that. I think the "|" has a precedence you don't expect. This modified version works for all 3 input types:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^\&lt;(.*?)\%\&gt; \/ \&lt;(.*?)/(.*?)\&gt;( vs. \&lt;(.*)\&gt;)?| (\+[\d,]+ Max Powerlevel)?$"
   regexp="y"
   repeat="y"
   send_to="2"
  >
  <send>%%1 = %1
%%2 = %2
%%3 = %3
%%4 = %3</send>
  </trigger>
</triggers>


Here is my test results from the lines you supplied:


<100%> / <8,291/8,291>
%1 = 100
%2 = 8,291
%3 = 8,291
%4 = 8,291
<98%> / <7,056/7,895> vs. <232>
%1 = 98
%2 = 7,056
%3 = 7,895
%4 = 7,895
<100%> / <7,450/7,895> +197 Max Powerlevel
%1 = 100
%2 = 7,450
%3 = 7,895
%4 = 7,895

#4
That's awesome. The only problem I see with your trigger is the fact that I need all the numbers to be wild cards.

I don't know what I'd do to change what you have to be all wild cards.
#5
Started playing with it. Works great. I only got a short chance to check out that trigger and what it actually did. I understand what it does now, I never thought to try it the way you did.

Now it's just a matter of condensing the cosiderable amount of code that I have in the other triggers, all into that one.

Thanks a bunch Nick, your program is amazing, and the fact that you take time to go through damned nearly every post and atleast comment really shows you care. It must be one busy day for you.
#6
After trying to get the +232 Max Power Level part to be captured as a wildcard, I've totaly messed it up... I can't figure it out. I guess it'd help if I haven't been up for 18 hours... Maybe I'll have figured it out by tommorrow, if you haven't already posted why it isn't working by then.
#7
I tried something. It worked... I don't know if there is a better way to do this, but this worked.
<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   keep_evaluating="y"
   match="^\&lt;(.*?)\%\&gt; \/ \&lt;(.*?)/(.*?)\&gt;(( vs. \&lt;(.*)\&gt;)?| (\+(.*?) Max Powerlevel)?)$"
   regexp="y"
   repeat="y"
   send_to="2"
  >
  <send>%%1 = %1
%%2 = %2
%%3 = %3
%%6 = %6
%%8 = %8</send>
  </trigger>
</triggers>
Just what the Doc ordered.

EDIT: Is this an advanced type of Reg Exp trigger? Or is this fairly common?
Amended on Thu 02 Feb 2006 08:30 AM by David Berthiaume
#8
<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   expand_variables="y"
   match="^\&lt;(.*?)\%\&gt; \/ \&lt;(.*?)/(.*?)\&gt;(( vs. \&lt;(.*)\&gt;)?| (\+(.*?) Max Powerlevel)?)$"
   regexp="y"
   repeat="y"
   send_to="12"
  >
  <send>maxpl = "%3"
form = "@Form"
SetVariable "MaxPowerLevel", maxpl
if form = "Super Saiyan" then
expectedgain = Int((maxpl / 2) * .05)
elseif form = "Super Saiyan 2" then
expectedgain = Int((maxpl / 3) * .05)
elseif form = "Super Saiyan 3" then
expectedgain = Int((maxpl / 4) * .05)
elseif form = "Ultimate Super Saiyan" then
expectedgain = Int((maxpl / 2) * .05)
elseif form = "2" then
expectedgain = Int((maxpl / 1.25) * .05)
elseif form = "3" then
expectedgain = Int((maxpl / 1.75) * .05)
elseif form = "4" then
expectedgain = Int((maxpl / 2.625) * .05)
else
expectedgain = Int(maxpl * .05)
end if

gain = "%8"
gamesessiongain = Int(GetVariable("GameSessionGain")) + gain
powerlevelgain = Int(GetVariable("PowerLevelGained")) + gain
SetVariable "PowerLevelGained", FormatNumber(powerlevelgain,0,0,0,-1)
SetVariable "GameSessionGain", FormatNumber(gamesessiongain,0,0,0,-1)
Note "Current gain is: +" &amp; FormatNumber(powerlevelgain,0,0,0,-1) &amp; "  |  Expected Gain is: +" &amp; FormatNumber(expectedgain,0,0,0,-1)</send>
  </trigger>
</triggers>


Current trigger

Current problem:
Error number: -2146828275
Event:        Execution of line 23 column 1
Description:  Type mismatch: 'gain'
Line in error: 

Called by:    Immediate execution


Edit: I just realized what the problem is...

It's looking for the Wildcard %8 when there is no wild card present in the base form sooooooo It triggers that error.

Ok. Now I have no idea what to do.
Amended on Thu 02 Feb 2006 08:44 AM by David Berthiaume
Australia Forum Administrator #9
Sometimes wildcard 8 doesn't exist, as you noticed. You can use GetTriggerWildcard to see if it exists or not, and retrieve its value. That might be safer:


http://www.gammon.com.au/scripts/doc.php?function=GetTriggerWildcard
#10
How do I do this from inside the trigger itself? I am not calling from a sub. I'm doing it all from within the trigger.

x = GetTriggerWildcard ("8")

Will that work?

Or does it have to have a trigger name?

x = GetTriggerWildcard ("", "8")
Amended on Thu 02 Feb 2006 11:26 PM by David Berthiaume
Australia Forum Administrator #11
Yes, you have to give it the name of the trigger, as the documentation said. You can still access the name with "send to script", like this:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="Exits: *"
   name="mytrigger"
   send_to="12"
   sequence="100"
  >
  <send>Note (GetTriggerWildcard ("mytrigger", 1))
</send>
  </trigger>
</triggers>

#12
Ok, I see what you are saying. I understand how GetTriggerWildcard works now.

However, I am still having the same problem...

How do I get it to ignore an emply wildcard?

If it comes back as an empty string, and the wildcard is not there, I want it to do nothing... but carry on as usual, but if it comes back as there being a value in the string and the wildcard is there, I got all kinds of things I want it to do.
#13
Right then, this is what I got so far. I'm certain there is a better way to do this, but I only have help files to go on.
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="^\&lt;(.*?)\%\&gt; \/ \&lt;(.*?)/(.*?)\&gt;(( vs. \&lt;(.*)\&gt;)?| (\+(.*) Max Powerlevel)?)$"
   name="Prompt"
   regexp="y"
   repeat="y"
   send_to="12"
  >
  <send>myen = GetTriggerWildCard ("Prompt", 1)
mypl = GetTriggerWildcard ("Prompt", 2)
mxpl = GetTriggerWildcard ("Prompt", 3)
mbpl = GetTriggerWildcard ("Prompt", 6)
if isempty (mbpl) then
else
ColourNote "white", "red", mbpl
end if
gain = GetTriggerWildcard ("Prompt", 8)
if isempty (gain) then
else
ColourNote "white", "red", gain
end if</send>
  </trigger>
</triggers>
The only problem with this trigger is that it keeps two empy spaces below the trigger for the notes, as though it's trying to world.note something(meaning, the space is there as if it's noting a blank line), but it isn't noting anything. I tried getting it to Note "wildcard is not present" when the wildcard wasn't present, but it did not work.

Please however note, that when the wildcard IS there, it does note the wild card properly.
Amended on Fri 03 Feb 2006 01:11 AM by David Berthiaume
#14
I've been playing with this isempty for HOURS now. It doesn't work. I've tried various permutations on it. I can not get it to work.
Australia Forum Administrator #15
You have misinterpreted the documentation slightly. It says the returned results are:


The contents of the specified trigger wildcard, as described above.

An EMPTY variant, if the trigger does not exist.
A NULL variant if the trigger name is invalid.
An empty string if the wildcard does not exist.


An empty variant is something you test with "IsEmpty" - that is returned if the trigger does not exist. However your trigger does exist.

An empty string is what is returned if the wildcard does not exist. An empty string is this: "".

So your code should read like this:


if gain <> "" then
  ColourNote "white", "red", gain
end if

Australia Forum Administrator #16
I have amended the documentation for GetTriggerWildcard to make that a bit clearer.


You can test this sort of thing yourself. I did this:


Note (VarType (GetTriggerWildcard ("mytrigger", 1)))
Note (VarType (GetTriggerWildcard ("mytrigger", 8)))


It was clear from the results (8 and 8) that I was getting a string result, however in the second case the string was an empty string.

See the VBscript documentation for the meaning of VarType:


vbEmpty     0 Empty (uninitialized) 
vbNull      1 Null (no valid data) 
vbInteger   2 Integer 
vbLong      3 Long integer 
vbSingle    4 Single-precision floating-point number 
vbDouble    5 Double-precision floating-point number 
vbCurrency  6 Currency 
vbDate      7 Date 
vbString    8 String 
vbObject    9 Automation object 
vbError    10 Error 
vbBoolean  11 Boolean 
vbVariant  12 Variant (used only with arrays of Variants) 

Amended on Fri 03 Feb 2006 05:17 AM by Nick Gammon
#17
Thanks a bunch Nick, I greatly appreciate it.

I can't even tell you how frustrated I was. I'm glad you noticed that I was misunderstanding what it meant. Cause I had no idea.

But It's working perfectly now.

Final Trigger:
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="^\&lt;(.*?)\%\&gt; \/ \&lt;(.*?)/(.*?)\&gt;(( vs. \&lt;(.*)\&gt;)?| (\+(.*) Max Powerlevel)?)$"
   name="Prompt"
   regexp="y"
   repeat="y"
   send_to="12"
  >
  <send>maxpl = GetTriggerWildcard ("Prompt", 3)
form = "@Form"
SetVariable "MaxPowerLevel", maxpl
if form = "Super Saiyan" then
expectedgain = Int((maxpl / 2) * .05)
elseif form = "Super Saiyan 2" then
expectedgain = Int((maxpl / 3) * .05)
elseif form = "Super Saiyan 3" then
expectedgain = Int((maxpl / 4) * .05)
elseif form = "Ultimate Super Saiyan" then
expectedgain = Int((maxpl / 2) * .05)
elseif form = "2" then
expectedgain = Int((maxpl / 1.25) * .05)
elseif form = "3" then
expectedgain = Int((maxpl / 1.75) * .05)
elseif form = "4" then
expectedgain = Int((maxpl / 2.625) * .05)
else
expectedgain = Int(maxpl * .05)
end if

sleep = GetVariable("Sleep")
gain = GetTriggerWildcard ("Prompt" , 8)

if sleep = "sleeping" then
if gain &lt;&gt; "" then
gamesessiongain = Int(GetVariable("GameSessionGain")) + gain
powerlevelgain = Int(GetVariable("PowerLevelGained")) + gain
SetVariable "PowerLevelGained", FormatNumber(powerlevelgain,0,0,0,-1)
SetVariable "GameSessionGain", FormatNumber(gamesessiongain,0,0,0,-1)
Note "Current gain is: +" &amp; FormatNumber(powerlevelgain,0,0,0,-1)
end if
end if
SetVariable "Expectedgain", expectedgain</send>
  </trigger>
</triggers>
Works like a charm with a few other triggers I have.