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
havelock
Newbie


Joined: 16 Sep 2003
Posts: 2
Location: USA

PostPosted: Tue Sep 16, 2003 11:50 pm   

Assigning string w/ variable # of words2 avariable
 
Hi, I'm pretty new to zmud, so this maybe simple or a function I haven't found. In the mud I play there is an auction channel and the items put up for auction have names with variable numbers of words in them. For example "a sigil mace" or "great whopping sword of destruction" or whatever. What I am trying to do is assign the whole string of text that comes up matching my auction trigger to a single variable, so I can trim it down to just the item name using %right and %left string commands.

My problem is that I can only see ways to assign a single word to a variable. Which means I would need perhaps as many as 6 sets of triggers to catch all of the items ranging from a single word up to six word long item names.

The inital trigger's pattern looks like so:
^AUCTION: (%a) bids (%d%p%d) gp on *.

And the value it executes is this:
#SHOW %1 bids %concat( %2, %3) on
#T+ AucItem

This gets me the name of the bidder and the amount of gold from 1,000 to 999,999 displayed. My mud outputs gold with comma seperations and I need to convert that to an actual number I can use the #ADD command on. The pattern of the 2nd trigger which is in the Class AucItem:
gp on *.

Pattern:
#SHOW %right( %1,5)
#T- AucItem

I have this in a subclass that will only be active immediately after the first trigger fires because it's pretty broad and I don't want anyone else to be able set it off. This is incomplete obviously, but hopefully it shows the direction I'm trying to go in. In place of the asterick, I'd like to be using something like (%a) but it has to be able to capture more than just one word. All of the pattern matching wildcards I can find are limited either to specificly numbers, words, non-whitespace or whitespace.

I'm using the #SHOW commands so I get output to determine how things are working. I'll replace those later with code to bump up the bid amount and place my bid in turn.

My question is how do I assign a string of multiple words to a variable in a trigger?

Grateful for any help,
Havelock
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Sep 17, 2003 12:55 am   
 
What's wrong with using *?
You can use %n for numbers which contain commas.
Be careful not to match your pattern with #SHOW. That's just asking for an infinite loop.

Pattern:
^AUCTION: (%a) bids (%n) gp on (*).
Value:
#SHOW %1 bid %2 on %3
#VAR bidder {%1}
#VAR bid {%2}
#VAR biditem {%3}
Reply with quote
user0101
Apprentice


Joined: 01 Aug 2003
Posts: 100
Location: USA

PostPosted: Wed Sep 17, 2003 1:12 am   
 
#TRIGGER {^AUCTION: (%a) bids (%d)(%p)(%d) gp on (*).} {#VAR yourvariablename %concat( %2, %4)}
#T+ AucItem

To store multiple words into a trigger, just enclose the specified portions of the string in parenthesis and call them with curley braces around the wildcard portion of your #VAR statement:

#VAR variablename {%5}

So let's say you want to store everything that is received from your last wildcard.

Auction: JoeSchmoe bids 1,000 gold on a vibrating stick.

With those two pieces of code you would store '1000' into 'yourvariablename', and 'a vibrating stick' into 'variablename'.

EDIT- Blasted Lightbulb, too fast for me! Hmm yea missed the part about wanting to manipulate it with #ADDI. Use Bulbs with the multiple variables instead of mine, and concat both vars together on a separate step.
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Wed Sep 17, 2003 1:17 am   
 
#TRIGGER {^AUCTION: (%w) bids (%n) gp on (*).} {#var bidder %1;#var bidamt %2;#var biditem "%3";#say @bidder bidded @bidamt of gold for @biditem}

I like to put the " " around the longer variables to make sure all of it gets captured.

this little extra step has saved me a lot of time in the past and continues to serve me well.
Reply with quote
havelock
Newbie


Joined: 16 Sep 2003
Posts: 2
Location: USA

PostPosted: Wed Sep 17, 2003 2:01 am   
 
Thanks a bunch.

Lightbulb's solution fit in so neatly, I don't need to mess with %right and %left at all. And I didn't realize %n took comma's.

Thanks for answering!
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