|
Gotanda Newbie
Joined: 11 Sep 2004 Posts: 7
|
Posted: Sat Sep 11, 2004 9:15 am
Help me capture number and put it into a variable |
I would like to capture this line whenever it comes up on the screen: (its not the beginning nor the end of the line)
Gotanda [100%H
However I want it to recognize that Gotanda is set as @tank and I wish to put the percentage (in this case his hps) into a variable. I have tried several different things but doesent seem to work with 7.05 (same pattern/value worked in previous versions however)
Just for reference this is what it said, while the trigger still worked:
pattern: @tank ~[(%d)~%~H (tank is set as Gotanda)
value: #var leader %2 |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sat Sep 11, 2004 10:01 am Re: Help me capture number and put it into a variable |
I assume 'leader' is the variable that should be set to the hp? As you have it now you are referencing a subpattern that doesn't exist. The first % variable is %1 and gets the first sub pattern. As (%d) is the first pattern surrounded by parantheses %1 should be used to retrieve it.
The correct command then becomes: #var leader %1
So this isn't a bug in zMUD. That it worked in earlier versions would have been the bug. |
|
|
|
Gotanda Newbie
Joined: 11 Sep 2004 Posts: 7
|
Posted: Sat Sep 11, 2004 12:24 pm |
hehe, i made typo of course :) sorry about that, I have written %1 and it still doesent work.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Sep 11, 2004 1:46 pm |
Put braces around the tank variable in the pattern. With the recent change to the underlying pattern engine zMud has become more particular about sloppy syntax in patterns.
As always I tell people to get in the habit of using proper delimeters in scripts. This habit adds some extra one where they aren't actually needed, but saves a headaches when they are needed. Added braces around the %1 as well since they are the right ones to use.
Pattern: {@tank} ~[(%d)~%H
Value #VAR leader {%1} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sat Sep 11, 2004 2:23 pm |
Vijilante wrote: |
Put braces around the tank variable in the pattern. With the recent change to the underlying pattern engine zMud has become more particular about sloppy syntax in patterns.
|
In that case the manual is wrong. Take a look at the help section "Pattern Matching". There it says "@variable match any of the specified strings or keys works with string lists and record variables". The {val1|val2...|valn} syntax should be used when you enter the strings yourself according to the manual. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Sep 11, 2004 3:28 pm |
The original pattern works with @tank set to Gotanda (tested in v7.05). I made up a test-line where the pattern would not be at either the beginning or end of the line.
#VAR tank Gotanda
#TR {@tank ~[(%d)~%~H} {#VAR leader %1}
#SHOW {1 Gotanda ~[83%H 92%M 87%V~]}
#VAR leader
The most common culprit when this sort of trigger doesn't work is extra spaces which appear in the MUD output but not in the pattern. In many cases, the number of extra spaces changes to keep columns lined up. In such a case, use %s to match those spaces.
Yes, the current Pattern Matching help is wrong. @variable (without curly braces) will work for a single-value variable, but it has always (or at least since v5.55) been necessary to use braces to match a list- or record-variable. Since a single-value variable is also a one-item list, using {} around the variable-name will always work and should be encouraged. |
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
Gotanda Newbie
Joined: 11 Sep 2004 Posts: 7
|
Posted: Sun Sep 12, 2004 12:14 am |
Thanks LightBulb, seems like we are getting close but still not working. It works fine when Im using your #show string, but that is not how it actually looks. When it gets the actual string it still doesent recognize it, let me show you how it looks:
01. [50 Ne/Ne] Gotanda [100%H 100%M 100%V] 51.16% (Leader)
^^^ (this percentage I wish to capture)
(now there are alot of spaces there, i hope this forum will keep em there after the post)
I cant see how this would differ from LightBulb's string however...
Thanks for help btw |
|
|
|
Gotanda Newbie
Joined: 11 Sep 2004 Posts: 7
|
Posted: Sun Sep 12, 2004 12:15 am |
Naturally, it is not the 01. line I wish to capture but the 100%H line. The Forum obviously didnt keep the correct spacing Sorry about that!
|
|
|
|
Gotanda Newbie
Joined: 11 Sep 2004 Posts: 7
|
Posted: Sun Sep 12, 2004 12:36 am |
Ok this is what I got and will work pretty well:
#TR {@tank %s~[%s(%d)~%~H} {#VAR leader %1}
So without the second %s it captures the 100% fine, aslong as the tanks hps is full that is, however assoon as it falls below and the mud creates a space like Gotanda [ 50%H instead of Gotanda [100%H it didnt work anymore so I added the second %s and now it works fine to capture anything below 100% (which is want I want, I actually dont need it at 100) however it is silly that I cant get it bulletproof, am I missing something with the second %s string? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Sep 12, 2004 3:51 am |
The %s expects at least one space. You should use a fixed width pattern to capture the actual percent number.
#TR {@tank %s~[(&3)~%~H} {#VAR leader {%trim(%1)}}
Again actual text from the mud makes all the difference in getting the answer right in the first place. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
|
|