|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Tue Jan 27, 2004 8:17 pm
Saving multiple lines to a var |
I am trying to create some sort of trigger that would save the contents of my backpack to a variable in list form, but i don't know how to get it to save multiple lines when there aren't always the same # of lines. Here is an example of mud output:
backpack (used) :
a lantern
a lantern
a lantern
a lantern
a large slab of meat
a light hauberk of oiled chainmail
a water skin
a water skin
a bridle made of leather
a rusty dagger
a dirk
a black stable ticket
a war saddle with stirrups
a receipt
After the last line, there is a blank line in the mud output. Is there any way i could set it up so that the trigger adds every item past the "backpack (used) : " line and stops at the blank line? Thnx in advance for the help, i'm not very good at zmud yet. :D |
|
|
|
Valint Wanderer
Joined: 12 Nov 2003 Posts: 70 Location: USA
|
Posted: Tue Jan 27, 2004 10:13 pm |
You might find the section on advanced triggers helpful <http://www.zuggsoft.com/library/trigadv.htm>
What you're looking for is something along the lines of:
#TRIG invTrig {backpack ~(used~)} {#VAR inventory %null;#TEMP {^$} {#STATE invTrig 0}}
#COND {} {#VAR inventory %additem(%line, @inventory)} {LoopLines|Param=99} |
|
|
|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Wed Jan 28, 2004 12:11 am |
Ok, i think i've got the basics now. I'm still having some trouble with another part of my thing, though. I'm trying to make it so that when i take something from my pack or put something in, it is added or deleted from the list. Here's what I have so far:
#TRIG invTrig {backpack ~(used~)} {#VAR inventory %null;#TEMP {^$} {#STATE invTrig 0}}
#COND {} {#VAR inventory %additem(%line, @inventory)} {LoopLines|Param=99}
#TRIG {You get (*) from a backpack.} {#VAR inventory %delItem( "%1", @inventory)}
#TRIG {You put (*) in a backpack.} {#VAR inventory %addItem( "%1", @inventory)}
For some reason, the bottom two triggers aren't working right. What am i doing wrong?
(Btw, mud output is:
You put a black stable ticket in a backpack.
You get a black stable ticket from a backpack.
so as far ias i can see, it should be working :P) |
|
|
|
Lench Beginner
Joined: 26 Jan 2004 Posts: 21 Location: Norway
|
Posted: Wed Jan 28, 2004 2:14 am |
im a total newbie about this but i think if you do %1 in the trigger aswell, it would work.
dont think wildcards like ? * stores it for later use....
And i also think if the name of the item is longer than 1 word, like a black shirt or similar, "%1" will be needed...but again not sure. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Jan 28, 2004 7:54 am |
The bottom two triggers work as far as I can tell. The "get" trigger removes the first matching item from the list and the "put" trigger adds the new item to the end of the list.
It's likely that the problem is in your first trigger, which uses %line. If the line happens to begin or end with extra spaces, those spaces are included in the item. When you later remove the item from the backpack, there are no extra spaces, so what you removed doesn't match the item in the list.
Use %trim to prevent this from happening. |
|
|
|
Aarlot Adept
Joined: 30 Dec 2003 Posts: 226
|
Posted: Wed Jan 28, 2004 8:41 am |
Ok, that makes sense, but where/how do i use %trim? :P
|
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Wed Jan 28, 2004 1:24 pm |
Off the top of my head I believe that would have to be
#COND {} {#VAR inventory %additem(%trim(%line), @inventory)} {LoopLines|Param=99} |
|
|
|
|
|