Exp trigger

Posted by Stepelista on Tue 08 Sep 2009 08:10 AM — 10 posts, 41,249 views.

#0
Grettings,

My score looks like this,

-------, the dunedain -------
You are sitting down, relaxing peacefully.
HP: 240/240 END: 240/240 Avg. Stats: 103 Quests done: 125
Current exp: 12734961 (for 3.3 extra levels) Total exp: 12734961
Strength: 103 Agility: 103 Charisma: 103
Constitution: 103 Coordination: 103 Intelligence: 103
Level -- thief, --d --h --m --s old.

My trigger is;

^Current exp: (\w+) ((\w+)% for level) Total exp: (\w+)$
(todo)
setvariable "Exp", "%1"

send to: script
enabled, regular expression, repeat on the same like, expand variables are checked. I also have the same lined trigger as expdiff, but none of them are firing, any idea?
#1
The first thing I can see is that \w is for word characters \d is for digits.
#2

^Current exp\: (\d+) \(for (\d+\.\d+) extra levels\) Total exp\: (\d+)$

Will capture the third line of that output assuming extra levels always has a decimal.
#3
Nick has a good tutorial.
Template:regexp
Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.

And you can use a site like this to build regular expressions.
http://www.regextester.com/
Amended on Tue 08 Sep 2009 08:31 AM by Blainer
Australia Forum Administrator #4
Quote:

(for 3.3 extra levels)


Your trigger:


((\w+)% for level)


You can't just change the word order like that. Is it "for x levels" or "x for level"?

Copy and paste the line you are trying to match to at least get the order of things right.
#5
^Current exp: (\d+) ((\d+)% for level) Total exp: (\d+)$

This one didn't work, I had one working before they changed the score design. I was using (\*?) on that one, I have read some posts about exp triggers, that's why I changed it to (\w+) I want it to capture my current exp. Variables will remain same as the old one was working. I just need a new trigger name to capture my current experience. %1 one.
Australia Forum Administrator #6
Please look at what you are trying to match:


Current exp: 12734961 (for 3.3 extra levels) Total exp: 12734961


Your trigger will not match:


^Current exp: (\w+) ((\w+)% for level) Total exp: (\w+)$


For one thing, the word "extra" appears in the line, but is not in your trigger.

And, as Blainer said, \w matches a "word" character. From the help: "A "word" character is any letter or digit or the underscore character".

For pure numbers you should be using \d (digits). However that won't match the "3.3" (as in 3.3 extra levels). A better match there would be: [0-9.]+

That would match digits and decimal points.
#7
I have read them all, it's just eating my mind, I couldn't write a trigger like which captures only the first digits...


Current exp: 1127772 (25% for level) Total exp: 1127772

I don't care about the (....) thing and total exp, what should I do to just ignore them? I only want my client to capture Current exp: (\d+)

Thanks for the tips you wrote, I have read them and they were very useful but I just couldn't figure it out...
#8
This should only capture "Current exp" as %1.

<triggers>
  <trigger
   enabled="y"
   match="^Current exp\: (\d+) \(\d+\% for level\) Total exp\: \d+$"
   name="Current_Exp"
   regexp="y"
   sequence="100"
  >
  </trigger>
</triggers>


The first set of brackets (\d+) is captured first to %1 and the second set of brackets to %2. We have only one set of brackets in the regex above so there is only %1. To include brackets in text to match you need to escape them with a backslash \ like this \(text\).
In the example above we need to match brackets around this part (25% for level) but not capture it so they need to be escaped with a backlash in front of each bracket \(\d+\% for level\).
Amended on Sun 13 Sep 2009 11:33 PM by Blainer
Australia Forum Administrator #9
Well:


Current exp: * (*


(Not a regular expression).

Wildcard 1 will be current experience, and wildcard 2 everything else you don't care about.