Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: 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
Reply with quote
Valint
Wanderer


Joined: 12 Nov 2003
Posts: 70
Location: USA

PostPosted: 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}
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: 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)
Reply with quote
Lench
Beginner


Joined: 26 Jan 2004
Posts: 21
Location: Norway

PostPosted: 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.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: 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.
Reply with quote
Aarlot
Adept


Joined: 30 Dec 2003
Posts: 226

PostPosted: Wed Jan 28, 2004 8:41 am   
 
Ok, that makes sense, but where/how do i use %trim? :P
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: 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}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net