|
shaun.murray Magician
Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Thu Jul 24, 2008 1:42 am
regex trigger - for working with doors |
I've got it, almost... Two different lines.
The closed gate block(s) your passage down.
The closed shady door block(s) your passage east.
Here is what I've got, each trigger works for the lines, but I want to combine them, but not sure how.
Code: |
#regex {^The closed (\w+\s+\w+) block\(s\) your passage (?=north|south|west|east|up|down)(\w+).$} {#window output open %concat(%2,".",%1);#window output %2;#switch (%2 = "north") {#window output close %concat(south,".",%1)} (%2 = "south") {#window output close %concat(north,".",%1)} (%2 = "west") {#window output close %concat(east,".",%1)} (%2 = "east") {#window output close %concat(west,".",%1)} (%2 = "up") {#window output close %concat(down,".",%1)} (%2 = "down") {#window output close %concat(up,".",%1)}}
#regex {^The closed (\w+) block\(s\) your passage (?=north|south|west|east|up|down)(\w+).$} {#window output open %concat(%2,".",%1);#window output %2;#switch (%2 = "north") {#window output close %concat(south,".",%1)} (%2 = "south") {#window output close %concat(north,".",%1)} (%2 = "west") {#window output close %concat(east,".",%1)} (%2 = "east") {#window output close %concat(west,".",%1)} (%2 = "up") {#window output close %concat(down,".",%1)} (%2 = "down") {#window output close %concat(up,".",%1)}} |
The output in the window "output" works. But like I said, Just curious how to combine them, and STILL use the anchor and foot to terminate the end of the lines. TIA! Still reasearching the regex, liking it so far. =] |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Thu Jul 24, 2008 2:10 am |
Using your existing code as much as possible:
Code: |
^The closed ((?:\w+)(?:\s\w+)?) block\(s\) your passage (?=north|south|west|east|up|down)(\w+).$ |
or to match extra words before block (above is 1 or 2 words only):
Code: |
^The closed ((?:\w+)(?:\s\w+)*) block\(s\) your passage (?=north|south|west|east|up|down)(\w+).$ |
And you could change the \w for \a if you don't want to match numbers, which I suspect is the case (didn't test though).
Perhaps the most complex regex I've made! <-- Very proud of himself! (I usually use zScript patterns.)
Some expert is now going to come along and tell us how much faster it would be if they made it more complex and completely unreadable I expect! |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Thu Jul 24, 2008 2:57 am |
Hmm, this might be a bit more efficient:
Code: |
^The closed ((?:\w++)(?:\s\w+)?) block\(s\) your passage (?=north|south|west|east|up|down)(\w+).$ |
|
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Thu Jul 24, 2008 4:07 am |
Hmm, I might go with:
Code: |
^The closed (.*?) block\(s\) your passage (north|south|west|east|up|down)\.$ |
The first change is because I might not be sure that there would only be one or two words between "closed" and "block". And there's enough anchoring words to just do an unrestricted wildcard.
The second change is that the lookahead seems pointless, if you are then going to collect that word too.
And there was a \ missing before the last period. |
|
|
|
shaun.murray Magician
Joined: 23 Jul 2005 Posts: 334 Location: Chicago
|
Posted: Thu Jul 24, 2008 1:11 pm |
Hrmm... So far, so good. However, say for example the door is locked?
The closed and locked gate block(s) your passage north.
Seb's solutions works fine with preventing the double trigger fire, and... I'm fairly certain that there is no doors/gates/ect that go beyond two words, so I'm pretty safe with just doing it that way. Its not that the wild card solution that Zhiroc gave doesn't work, but I forgot about the locked doors as well, and it was starting a door trigger firing war. LoL! Thanks everyone! =] |
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Thu Jul 24, 2008 6:08 pm |
"closed and locked gate block(s)" already has 3 words between the end words. Doesn't the pattern fail to match? Oh, I see, Seb's 2nd pattern also allows any number of words. But I'm not sure it's any more efficient than just a "(.*?)", which is also easier to understand, and you'll run into problems if the door ever has punctuation, like "swinging-door". But that might never come up.
Since you capture the text of the door, you can handle locked ones by pattern searching %1 for the word "locked" (presuming that is a constant). Your script can then do what it needs to. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Fri Jul 25, 2008 10:05 am |
I think shaun.murray already has a trigger for closed and locked doors? And that he didn't want this trigger to match them?
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|