Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ Different responses to similar trigger texts (bad description, I know)
|
Different responses to similar trigger texts (bad description, I know)
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Bobble
Canada (76 posts) Bio
|
| Date
| Fri 11 Apr 2003 10:52 PM (UTC) |
| Message
| I'm having a difficult time with what, to me, seems like a truly simple problem. But I think my relative newbieness to scripting and creating triggers is hampering me. On one MUD I play, there are two different "afflictions" you can be given which have similar trigger texts. Each trigger requires a different response.
The first trigger text is:
A prickly, stinging sensation spreads throughout your body.
The proper response is:
eat kelp
This I have no problem with. The difficult problem is there's another trigger text designed to beat triggers. What it does is it takes the same text:
A prickly, stinging sensation spreads throughout your body.
And randomly inserts two or three asterisks in place of some letters, for instance:
A pr*ckly, stingin* sensation spreads throughout your body.
The proper response to this is to:
eat bloodroot
Remember, the asterisks are randomly placed.
My original plan was to design two triggers, one that just simply matched the first trigger text and ate kelp and a second that was a regular expression using the |. i.e.
^(A|*) (p|*)(r|)(i|*) . . . etc.
that would eat bloodroot
I quickly realized however, that this setup will also match the text without the asterisks so I'd eat both kelp and bloodroot (which messes things up on the MUD). So no go there. What I thought would be wise would be to eliminate the first trigger and use the regular expression to call a subroutine that would search the text sent by the mud for an asterisk. If asterisk was true, eat bloodroot. If no asterisk, then eat kelp. For the life of me, I can't figure out how to do this.
I'm sure the solution is simple, I just haven't encountered the right function yet. Any help? |
Open the watch. | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #1 on Sat 12 Apr 2003 07:44 AM (UTC) |
| Message
| I could be fundamentally wrong on this - which would hopefully explain why I die so much - but the kelp and bloodroot messages are different. At least that's how it is in my list of triggers. The kelp message is shorter than the bloodroot one and misses the part about 'numbness'. Might want to check into it again to make sure. In case they are the same...
Since the asterixed message is always the bloodroot one, that already sets the two of them apart, due to the fact that the 'plain' trigger will never match on the 'asterixed' message. So you could distinguish between the two by their names, using the script obviously. And to ensure that the 'asterix' trigger won't match on the plain message first, bring the 'plain' trigger up in the sequence. That should prevent the regexp trigger matching on the kelp message.
However, I don't believe that the messages are really the same, though I'll get to checking it as soon as I am able to do so. If you are right then it looks like there's a serious hole in my triggers. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Sat 12 Apr 2003 08:10 AM (UTC) |
| Message
| If the two messages are the same, apart from the asterisks in the middle, use the regular expression you had, but have the trigger call a script that does an "Instr" on the matching text to see if there was an asterisk in their somewhere or not. Or, just compare for the complete, unasterisked message.
Or, again, have both messages in different triggers, and have the unasterisked one earlier (ie. with a lower sequence). Then if it matches the unasterisked one, it won't "fall through" and match the asterisked one. Then just have the two triggers send back the approriate response. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Bobble
Canada (76 posts) Bio
|
| Date
| Reply #3 on Mon 14 Apr 2003 06:23 PM (UTC) |
| Message
| Ked was correct the triggers actually use different text, so that problem is solved, however, my next problem is if I do use the A|\* regular expression, i get an error that says I have too many wildcards or something to that effect.
I know parsing has been mentioned before as a way to handle this, but I'm afraid I don't quite understand how this works. Would someone be able to give me an example of how I can keep all the wildcards in this regular expression without getting the error?
Thanks, and if you need more elaboration, please ask. |
Open the watch. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Mon 14 Apr 2003 10:08 PM (UTC) |
| Message
| Since you don't really need the individual letters returned as wildcards (you still get the whole line as wildcard 10) you can suppress that using ?: like this:
^(?:A|*) (?:p|*)(?:r|)(?:i|*) ... |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Bobble
Canada (76 posts) Bio
|
| Date
| Reply #5 on Mon 14 Apr 2003 10:28 PM (UTC) |
| Message
| Hi Nick,
Thanks a lot, I'll give it a try. Something I'm not clear on is what the : does. I know the ? matches zero or one of the previous character set, but what does the : do?
Anyone?
Thanks! |
Open the watch. | | Top |
|
| Posted by
| Ked
Russia (524 posts) Bio
|
| Date
| Reply #6 on Mon 14 Apr 2003 11:30 PM (UTC) |
| Message
| Taken from the regexp file in the Docs folder of Mushclient
? extends the meaning of (
also 0 or 1 quantifier
also quantifier minimizer
One way it extends the meaning of ( is when setting options. Have no idea what that does or if it's even supported by Mushclient. Another way is the (?: case. This basically means that you don't want this subpattern to be included in the list of captured ones, or in other words - it won't be captured as a wildcard. This allows you to use the () just as you could use [] only with more flexibility since () can include branches that match on more than 1 character, and relieves you of the worries about having more than a certain number of captured subpatterns in your expression. Just like in the case you were trying to solve.
Erm, : is also used in the POSIX character classes but I never got to figuring out those myself. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #7 on Tue 15 Apr 2003 12:40 AM (UTC) Amended on Tue 15 Apr 2003 12:44 AM (UTC) by Nick Gammon
|
| Message
| The meaning of ? is somewhat position-dependant. For example, after a character it simply means zero or one of that character.
eg.
ba?d would match on "bd" or "bad"
However after a bracket it takes on a different meaning, as it can hardly mean zero or one bracket, because the bracket is a meta-character.
Thus:
(?:bad) means match on "bad" but don't make it a wildcard.
If you had:
(bad) (dog)
If it matched, wildcard 1 would be "bad" and wildcard 2 would be "dog".
If you had:
(?:bad) (dog)
If it matched, wildcard 1 would be "dog" and wildcard 2 would be empty.
Interestingly, you can also have zero or one of a bracketed group, thus you could have:
This would match on "bad " and "bad dog" as you can have zero or one of the word "dog".
You can also use (? to set options by following the "?" by a letter.
For example, (?i) sets caseless matching.
As for POSIX character classes, these are done with square brackets within square brackets, like this:
This example would match a single character that was either "alpha" (letters or digits) or "xdigit" (hexadecimal digits).
This is all supported by MUSHclient. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
26,603 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top