having trouble with multi-line trigger

Posted by Lilbopeep on Fri 06 May 2011 07:36 PM — 8 posts, 34,497 views.

USA #0
I have been working on a stat roller but I can't seem to get a multi-line match going despite different attempts at the regexp based on other forum posts..



       Power: 19 (Strong)
Coordination: 14 (Nimble)
   Toughness: 15 (Fit)
Intelligence: 14 (Smart)
      Wisdom: 14 (Thoughtful)
  Appearance: 14 (Pretty)
       Karma: 14 (Lucky)
       Total: 104


The multi-line I have is:

^Power\:\s*(\d+)\s*\((.*?)\)\n\s*Coordination\:\s*(\d+)\s*\((.*?)\)\n\s*Toughness\:\s*(\d+)\s*\((.*?)\)\n\s*Intelligence\:\s*(\d+)\s*\((.*?)\)\n
\s*Wisdom\:\s*(\d+)\s*\((.*?)\)\n\s*Appearance\:\s*(\d+)\s*\((.*?)\)\n\s*Karma\:\s*(\d+)\s*\((.*?)\)\nTotal\:\s*(\d+)\Z

I basically added a colournote just to see if I could get a match, but it hasn't matched yet, as confirmed in the dialog box for the trigger.

its enabled, ignore case, keep evaluating, regular expression, multi-line match is set to 8, send to script

what am I doing wrong?
Amended on Fri 06 May 2011 07:59 PM by Lilbopeep
USA #1
Have you tried writing and testing one line at a time, to see if you can isolate a problem spot?

...also, I see "Power", "Coordination", "Toughness", "Appearance", "Karma" in the output, but "Strength", "Dexterity", "Constitution", "Charisma", "Luck" in your regexp. That's guaranteed not to match, regardless of any other errors you might have.

(By the way, I'd change the \((.*?)\) to \([^)]+)\), because .* and .*? can both take longer depending on backtracking. [^)] is guaranteed to stop only on a ).)
USA #2
Twisol said:

Have you tried writing and testing one line at a time, to see if you can isolate a problem spot?

...also, I see "Power", "Coordination", "Toughness", "Appearance", "Karma" in the output, but "Strength", "Dexterity", "Constitution", "Charisma", "Luck" in your regexp. That's guaranteed not to match, regardless of any other errors you might have.

(By the way, I'd change the \((.*?)\) to \([^)]+)\), because .* and .*? can both take longer depending on backtracking. [^)] is guaranteed to stop only on a ).)


err, yeah.. I copied the wrong thing. The names are correct, but no I haven't tried one line at a time.

Also are you sure \([^)]+)\) is correct? It gives me umatched parenthesis
USA #3
Lilbopeep said:
Also are you sure \([^)]+)\) is correct? It gives me umatched parenthesis

Nope, I'm totally unsure.

\([^\)]+)\)

Try that.
USA #4
I tried line by line like you suggested and it just left me more confused..

Since i was setting the numbers to variables (i.e. pow = tonumber (%1), coo = tonumber (%3)) in order to check for rolls later, it was giving me errors that made sense because I was trying to save where none existed. Each time I added a new stat and increased the multi-line by 1, I could see it matching and erroring on each stat. When I got to the last one and increased my line count to 8, it stopped matching.

I am noticing that sometimes the adjectives are sometimes two words and maybe this is causing the problem with matching correctly

this, btw, is still not working..

\([^\)]+)\)

still too many parentheses and im not sure which way to fix it
USA #5
Lilbopeep said:
(i.e. pow = tonumber (%1), coo = tonumber (%3))

Here's the thing. %1, @var, etc. are not part of Lua. MUSHclient directly inserts them into the script before it's run. So tonumber(%1) becomes tonumber(100)... but it's already a number, so you can just use %1 directly.

On the other hand, if there's a chance that %1 isn't a number, you need to use tonumber("%1"). The quotes mean that %1 is put into a string, and tonumber() then turns it into a number from within Lua. It'll give a runtime error, rather than a syntax error, if it's not a number.


Lilbopeep said:
\([^\)]+)\)

still too many parentheses and im not sure which way to fix it

Mrrrrgh. No, not enough parentheses. Lets try this again.
\(
 (
  [^\)]+
 )
\)


And... here. \(([^\)]+)\) If this doesn't work, I don't know what I'm going to do. X_X
USA #6
I had to take a break but when I came back I realized since the total is just that and I can account for the numbers that make it up, there's no reason to keep track of it and it's the only thing I ended up getting stuck on so I scrapped it.

Everything seems to be working great now, thanks for sticking with me on it, Twisol
USA #7
No problem! I'm glad you got it working.