Achius2008-07-11 17:14:10
Howdy, I play Daved and I'm in the process of creating my own system in zmud from scratch, figure I'll just put all of my questions in here, any help anyone can offer would be much appreciated
So, first question:
#if (%pos( "e", %4)) {#variable eq {1}} {#variable eq {0}}
#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}}
#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}}
#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}}
#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}
that is in my prompt trigger, where %4 refers to the 'elrx-' none of these work consistently, but rather they work sporadically. Why?
I should mention that this is my prompt detection trigger:
^(%d)h, (%d)m, (%d)e, %dp, %den, %dw (%w)-$
So, first question:
#if (%pos( "e", %4)) {#variable eq {1}} {#variable eq {0}}
#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}}
#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}}
#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}}
#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}
that is in my prompt trigger, where %4 refers to the 'elrx-' none of these work consistently, but rather they work sporadically. Why?
I should mention that this is my prompt detection trigger:
^(%d)h, (%d)m, (%d)e, %dp, %den, %dw (%w)-$
Unknown2008-07-11 17:55:28
So, your code is:
By the way, do you know or want to know about REGEX (Regular Expressions) within ZMUD, which will make your triggers run about twice as fast in the least and are a bit easier to read? They're not hard to convert to, and they're useful outside of making your own system.
CODE
#TRIGGER {^(%d)h, (%d)m, (%d)e, %dp, %den, %dw (%w)-$} {#if (%pos( "e", %4)) {#variable eq {1}} {#variable eq {0}};#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}};#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}};#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}};#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}} "prompt"
This looks solid from the office, but I can take a look at it in game when I get back. The only thing I can think of causing it to fail is if you create a situation when you don't have anything for the "elrxp" word capture. This might help your situation. A quick and dirty fix is this:CODE
#TRIGGER {^(%d)h, (%d)m, (%d)e, %dp, %den, %dw ()$} {#if (%pos( "e", %4)) {#variable eq {1}} {#variable eq {0}};#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}};#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}};#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}};#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}} "prompt"
If you haven't set the prompt option above, I highly recommend doing so, as the trigger will fire only on the prompt and not on every old line. Also, if that's your actual code copy and pasted from the ZMUD editor, you may want to remove the whitespace below the last line, as ZMUD can get somewhat pissy about whitespace regardless of settings.By the way, do you know or want to know about REGEX (Regular Expressions) within ZMUD, which will make your triggers run about twice as fast in the least and are a bit easier to read? They're not hard to convert to, and they're useful outside of making your own system.
Achius2008-07-11 19:58:33
Yes, I heard about this 'regex' but wasn't sure if it had to do with programming, or those of us attempting to learn programming :> But please, do tell
Unknown2008-07-11 20:19:26
A lot of pattern matching is based on Regular expressions or just plain uses them, so they're darned handy to know and understand. For Zmud they're just darn faster. More advanced clients support PCRE, or Perl-Compatible Regular Expressions. The in-depth stuff for normal regular expressions can be found here. If you're interested in PCRE for the sake of future clients or programming, you'll want to go here. I'll give you a rundown of how it works in ZMUD (and where zugg's own helpfiles are inaccurate). A lot of this can be found in ZMud's own helpfiles if you search for "#REGEX", though the client-side one has a few inaccuracies.
Here's a link to a small list of what REGEX expressions take the place of zuggsoft pattern matching.
The syntax for a regular expression trigger is:
To enable a regular expression within the GUI editor, just check the little box next to "PERL Regular Expression".
Regular expressions match patterns a lot like zuggsoft ones, but they're a heck of a lot smarter. For instance:
Just like zuggsoft pattern matching, there are a few characters you can't use as is. These special characters are:
Now, instead of using %whatever characters, you use different character codes within a regular expression. It's important to know that these only match ONE character.
That's about as illegible as it gets, but regular expressions have a few other special characters that make things easier. You can tack on the following special characters that do exactly as they're listed:
Just like with ZMUD triggers, if you want to capture something to %1..%99, enclose it in round brackets "()".
Example:
One of the bigger differences in regular expressions within ZMUD is that {} doesn't work quite the same way. In order to group things you need to use "?:" at the start of the grouping within round brackets. The "?:" at the start of the grouping prevents it from capturing the data to %1...%99.
Example:
From that you can start doing options within the group. Use the "|" character. Using the "|" character out of the group will probably mess up your entire trigger, as it will consider the entire trigger it's group in that instance.
Example:
In order to send data right to a variable, you can just insert the variable's name between the question mark and the colon.
Example:
Here's a link to a small list of what REGEX expressions take the place of zuggsoft pattern matching.
The syntax for a regular expression trigger is:
CODE
Syntax: #REGEX id {pattern} {commands} classname options
To enable a regular expression within the GUI editor, just check the little box next to "PERL Regular Expression".
Regular expressions match patterns a lot like zuggsoft ones, but they're a heck of a lot smarter. For instance:
CODE
#REGEX {dog} {do stuff here}
works just like CODE
#TRIGGER{dog} {do stuff here}
Just like zuggsoft pattern matching, there are a few characters you can't use as is. These special characters are:
CODE
, \\, ^, $, ., |, ?, *, +, (, and ).
The most important of these is "\\" as it's the escape character. That means that a character immediately after it will be processed as is. So if you want to match any of the special characters, you need to put a "\\" in front of it. Example:CODE
#REGEX {dog\\.} {do stuff here}
will match CODE
dog.
Now, instead of using %whatever characters, you use different character codes within a regular expression. It's important to know that these only match ONE character.
QUOTE
. matches any character. - Not advised for trigger use in ZMUD.
\\p the | pipe character - This is a LIE for ZMUD. The real code is \\|
\\w a word delimiter (matches a-zA-Z0-9) - Not advised for trigger use in ZMUD.
\\a a letter (matches a-zA-Z)
\\d a digit (matches 0-9)
\\h a hex character (0-9A-F)
\\s matches a space ( )
\\n matched a newline - for multiline triggers
Here's an example of their use:\\p the | pipe character - This is a LIE for ZMUD. The real code is \\|
\\w a word delimiter (matches a-zA-Z0-9) - Not advised for trigger use in ZMUD.
\\a a letter (matches a-zA-Z)
\\d a digit (matches 0-9)
\\h a hex character (0-9A-F)
\\s matches a space ( )
\\n matched a newline - for multiline triggers
CODE
#REGEX {\\w\\w\\w\\w\\w\\w\\w\\s\\a\\a\\a\\a\\a\\s\\d\\.} {do stuff here}
will match CODE
1Forget these 2.
That's about as illegible as it gets, but regular expressions have a few other special characters that make things easier. You can tack on the following special characters that do exactly as they're listed:
QUOTE
* match zero or more of the previous pattern
+ match one or more of the previous pattern
? match zero or one of the previous pattern
Example:+ match one or more of the previous pattern
? match zero or one of the previous pattern
CODE
#REGEX {\\w+\\s+\\a+\\s+\\d+\\.} {do stuff here}
will matchCODE
1Forget  these  245.
Just like with ZMUD triggers, if you want to capture something to %1..%99, enclose it in round brackets "()".
Example:
CODE
#REGEX {(\\w+)\\s+\\a+\\s+\\d+\\.} {do stuff here}
will matchCODE
1Forget  these  245.
with %1 being "1Forget".One of the bigger differences in regular expressions within ZMUD is that {} doesn't work quite the same way. In order to group things you need to use "?:" at the start of the grouping within round brackets. The "?:" at the start of the grouping prevents it from capturing the data to %1...%99.
Example:
CODE
#REGEX {(?:\\w+)\\s+\\a+\\s+\\d+\\.} {do stuff here}
will matchCODE
1Forget  these  245.
with %1 being unset.From that you can start doing options within the group. Use the "|" character. Using the "|" character out of the group will probably mess up your entire trigger, as it will consider the entire trigger it's group in that instance.
Example:
CODE
#REGEX {(\\w+\\d\\w+\\s+(?:\\a+|\\a+\\s+\\d+)\\.} {do stuff here}
will matchCODE
1Forget  these  245.
and CODE
1Forget  these.
with %1 being unset.In order to send data right to a variable, you can just insert the variable's name between the question mark and the colon.
Example:
CODE
#REGEX {(?firstword:\\w+)\\s+\\a+\\s+\\d+\\.} {do stuff here}
will matchCODE
1Forget  these  245.
setting "@firstword" to "1Forget".Achius2008-07-12 05:13:01
Very informative and helpful, thank you! Should I use these regex for every trigger then?
Moiraine2008-07-12 07:05:57
So how exactly would I use a regex to read the prompt status right, since the number of letters changes according to status?
Malarious2008-07-12 09:25:14
QUOTE(Moiraine @ Jul 12 2008, 03:05 AM) 531623
So how exactly would I use a regex to read the prompt status right, since the number of letters changes according to status?
You want to catch the 6th spot as a could be any or none kind of thing...
QUOTE
. match any single character
* match zero or more of the previous pattern
+ match one or more of the previous pattern
? match zero or one of the previous pattern
* match zero or more of the previous pattern
+ match one or more of the previous pattern
? match zero or one of the previous pattern
. matches any single, * matches more than one and ? allows it to match nothing at all.
And how do you use that?
To quote someone else..
CODE
#if (%pos( "e", %4)) {#variable eq {1}} {#variable eq {0}}
#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}}
#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}}
#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}}
#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}
#if (%pos( "r", %4)) {#variable rightarm {1}} {#variable rightarm {0}}
#if (%pos( "l", %4)) {#variable leftarm {1}} {#variable leftarm {0}}
#if (%pos( "x", %4)) {#variable legs {1}} {#variable legs {0}}
#if (%pos( "p", %4)) {#if ((!(%ismember( "paralysis", @focuslist))) and (!@writhelist)) {#variable prone {1}}} {#variable prone {0}}
Although you of course have to have %4 actually be the spot for those.. so it could be a few things, depending on if you are ignoring any at the time.
Hope that helps!
Unknown2008-07-13 14:33:17
Use Regex triggers for EVERYTHING. They are that much faster. You won't notice as much of a difference at first, but once your system gets larger, it'll shave about half of the processing time off.
CODE
^(?health:\\d+)h, (?mana:\\d+)m, (?ego:\\d+)e, (?power:\\d+)p (\\a*)-
At the end I have a capture that matches 0 or more letters for erlx: "(\\a*)"Charune2008-07-13 16:55:12
QUOTE(Eldritch Ex Machina @ Jul 13 2008, 10:33 AM) 531980
Use Regex triggers for EVERYTHING. They are that much faster. You won't notice as much of a difference at first, but once your system gets larger, it'll shave about half of the processing time off.
CODE
^(?health:\\d+)h, (?mana:\\d+)m, (?ego:\\d+)e, (?power:\\d+)p (\\a*)-
At the end I have a capture that matches 0 or more letters for erlx: "(\\a*)"As far as I was aware, ZMud patterns are stored for system processing as regex patterns, the difference being the regex patterns generated are usually a little more wide in what they match than if you were to write the regex yourself. If that's the case, the performance drop should not be that large, I'd think. Could be wrong about all of this though - I've been using KMuddy in Ubuntu for months now.
Unknown2008-07-14 03:49:58
They're actually a lot more wide. %w actually matches like .+ which is a huge problem for system performance and eats up heinous amounts of time on larger systems. I went down from about 0.300 seconds of zmud latency to about 0.120 seconds of zmud latency when I did the conversion. To me, that's enough to make a difference. Note that figures are for spamtastic combat and latency is for each second.
Unknown2008-07-14 11:04:30
I doubt that %w translates to .+, actually. There are characters that the %w wildcard doesn't capture, unlike .+...