 |
KiraDouji Newbie
Joined: 03 Jan 2004 Posts: 6
|
Posted: Sat Jan 03, 2004 8:10 am
I Just Want To Parse A String |
I'm trying to set up a trigger that will sort out my "rift" by taking the amount of something and putting it into a variable.
Eg:
<prompt> In the rift...
2 herb 4 inks 6 twigs
The trigger "%1 herb" allocates "2" to "@herb". However, no matter what I try I can't allocate "4" to "@inks". Either I get the whole line before it ("2 herb ") or nothing at all. I've tried to just grab the "4" with everything from * to %d, %a, %1, etc... to auto assigning it to a variable. (Inevitably, the variable ends up being "2 herb " or "2 herb 4"). Out of desperation I even tried forcing it to a number ("%number ~").
How the hell do you parse a string like this in Zmud? With all the built in stuff and the if statements I still can't get the stupid thing to just give me "4".
(And I have tried "%a %a %1 inks", and %1 would be 4, however, the problem then becomes how to get the number of twigs. Stuff moves around in the rift so I can't always be sure that there will be two "words" in front of the number of inks... next time the order could be twigs, herb, ink, depending on if I add anything to the "rift")
So if anyone could help me I'd really appreciate it. |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Jan 03, 2004 7:32 pm |
#TR {(%d) herb} {#VAR herb %1}
#TR {(%d) inks} {#VAR inks %1}
#TR {(%d) keys} {#VAR keys %1}
Nowhere is it written that thou shalt be limited to one trigger per line. |
|
|
 |
musishun00 Wanderer

Joined: 16 Dec 2003 Posts: 77 Location: USA
|
Posted: Sat Jan 03, 2004 7:39 pm |
Try this... I'm just doing this from memory, but I think it should work. This is, of course, assuming that all the items you have in the rift will only have single word descriptions.
2 herb 4 inks 6 twigs
#trigger {In the rift...} {#t+ inrift}
#class inrift
#trigger {(%n) (%w) (%n) (%w)} {#var %2 %1;#var %4 %3}
#trigger {WHATEVER YOUR STOPPING POINT IS} {#t- inrift}
#class 0
See if that works out for you.  |
|
|
 |
KiraDouji Newbie
Joined: 03 Jan 2004 Posts: 6
|
Posted: Sat Jan 03, 2004 9:59 pm |
Um, this might be a really silly question, but, where are you two typing in that syntax? I just hit the trigger button, and make a new one, and I'm pretty sure you don't type all that in "pattern" or "Value"
Uh, secondly... I don't think my Zmud is recognizing %d, because it never picks up anything. With %1-99 I get something in the variable, but with %d all I get is <empty>. |
|
|
 |
KiraDouji Newbie
Joined: 03 Jan 2004 Posts: 6
|
Posted: Sat Jan 03, 2004 10:04 pm |
quote: Originally posted by LightBulb
#TR {(%d) herb} {#VAR herb %1}
#TR {(%d) inks} {#VAR inks %1}
#TR {(%d) keys} {#VAR keys %1}
Nowhere is it written that thou shalt be limited to one trigger per line.
The main issue here is that the rift shifts depending on what I put into it, so the next day it could read 3 twigs 2 inks 1 herb and there wouldn't even be keys. Does this code take care of that and I'm just not seeing it? |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Jan 03, 2004 11:27 pm |
1. Type it into the command line. Or, in the trigger editor, type the first section of each trigger into the Pattern box and the second section into the Value.
#TR {Pattern} {Value}
2. %d is a standard wildcard, listed in the helpfile Pattern Matching topic, which matches any number of digits (0-9). It must be enclosed in parentheses if you want to use its value in the command (value) section of the trigger. %1 is a nonstandard wildcard, not listed in the Pattern Matching topic, which functions the same as * except it doesn't need parentheses. If %d doesn't give you anything, it's probably because you didn't put parentheses around it. However, if there are EXTRA spaces in the pattern between the number and the word, * (or %1) will match but %d won't.
For instance, if the MUD sends
3 twigs 2 inks 1 herb
then a pattern of (%d) ink will give %1 equals 2
but a pattern of %1 ink will give %1 equals 3 twigs 2
So, put in the right number of spaces and use (%d), it's a better choice.
3. Each trigger is designed to deal with one item. If an item is there, in any order, its trigger will pick it up. If it's not, that trigger won't fire. Since none of the triggers will have any effect on any of the other triggers, then YES that will take care of it having keys one day and twigs another. This is the advantage of not trying to force everything into a single trigger. But what you really aren't seeing is a method to clear the values before you check the rift. This was probably an oversight on my part, as many people won't realize the necessity, but I was focused on answering your question (how do you get the numbers for several different items from the same line).
4. A record variable would be a better choice since you then only have one variable to clear instead of having to keep track of several of them. You can clear a record variable by setting it to a null-string (#VAR rift ""}, deleting it (#UNVAR rift}, or setting each value to 0 (#LOOPDB rift {#ADDKEY rift {%key} 0). If you decide to use a record variable, you'll need to change the triggers to use #ADDKEY instead of #VARIABLE. Paste the following script in your command line, and add similar triggers for any other items you might find in your rift.
#TR {In the rift...} {#VAR rift ""}
#TR {(%d) herb} {#ADDK rift herb %1}
#TR {(%d) ink} {#ADDK rift ink %1}
#TR {(%d) key} {#ADDK rift key %1}
#TR {(%d) twig} {#ADDK rift twig %1}
5. If you stick with the previous script (individual variables), you'll still need to clear the variables by setting them to 0 or a null-string, or deleting them, and you'll have the additional problem of keeping track of all the variable names you're using. |
|
|
 |
mr_kent Enchanter
Joined: 10 Oct 2000 Posts: 698
|
Posted: Sun Jan 04, 2004 12:10 am |
Very nice Lightbulb. Your Record VAR idea and description was extremely helpful and appreciated.
|
|
|
 |
|
|
|
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
|
|