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
Sinema
Beginner


Joined: 14 Nov 2001
Posts: 27
Location: USA

PostPosted: Thu Jun 19, 2003 9:58 am   

Capturing Text
 
I will not pretend to know what I'm talking about but I have read a lot of the zMUD help file and am atleast trying to learn.

===

Here is the situation..

When I log on I get a list of people who have bought items from me online

I type a certain command and I see things in this format

10-9-2003 22:45> NAMEHERE bought "ITEM", Item description here for 1000 coins.

Is there a way to capture

the name and the abount of coins ?

Basically I get a lot of customers and it's hard to keep track of who buys what.

I was trying to see if there was a way that I can type

shoppers and when the scroll happens it catches the name and the amount and it adds it to a running total so at the end I can type something and it says

So and so spent this amount...

and it would do that for each person..

So if say Bob spent 1000 coins..on 5 items.. and Hank spent 5 coins on 5 items

when I typed the alise , the output would read

Bob spent 5000 coins
Hank spent 25 coins

Any help would be great.

~
Regards,

Sinema
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 19, 2003 2:22 pm   
 
The best way is to store the information in a record variable where each key is the name of a person and the associated value is the amount they spent. What you do then is to make the command that lists what each person bought into an alias that first clears the variable that will contain the information. Then triggers will capture the name of the person and how much they paid for the item and add it to whatever they already have paid so far using the #ADDKEY command. Finally, another alias will let you display the information stored in the variable by looping through each key-value pair using #LOOPDB. Here is an example (this assumes that your command for displayign what each person bought is called "sales"):
#ALIAS sales {#VAR moneySpent "";~sales}
#TRIGGER {*~> (%w) bought *, * for (%d) coins.} {#ADDKEY moneySpent %1 %eval(%db(@moneySpent, %1) + %2)}
#ALIAS showsSalesSummary {#LOOPDB {#SH %key spent %val coins.}}

There's a little trick in the trigger. If a key already exists, then the #ADDKEY command replaces it's value with the one you supply. For this reason, we need to find out the current value the key already has and then add to it the amount spent on this particular item. To avoid using more commands, I used the %db function to get the current value of the key and then the %eval function to add to that the amount spent on the current item. If the key does not exist already, %db return nothing wich %eval interprets as 0, so it works fine.

Kjata
Reply with quote
Sinema
Beginner


Joined: 14 Nov 2001
Posts: 27
Location: USA

PostPosted: Thu Jun 19, 2003 5:28 pm   
 
Thanks for going into detail, as I am trying to learn this as well.

I want to make sure I do this right so I have 2 other formats that are shown as well

BUYNAME bought the item of Name of Item, worth 3348 coins.

BuyName paid 10000 gold coins at ( Location ).

okay the first one I'm not so sure on as the "Name of item" isn't in quotes and sometimes as an extra , in it to break it up.

but the 2nd one I put this

#TRIGGER {*~> (%w) paid (%d) gold coins.} {#ADDKEY moneySpent %1 %eval(%db(@moneySpent, %1) + %2)}

Is that close? I did not know how to add the last part of the 2nd prompt.

Thanks for any help and for the help you've given as well.

~
Regards,

Sinema
Reply with quote
Sinema
Beginner


Joined: 14 Nov 2001
Posts: 27
Location: USA

PostPosted: Thu Jun 19, 2003 5:40 pm   
 
#LOOPDB {#SH %key bought %val coins.}
^ syntax error

Okay i used the above to test it out.

without any other triggers, just the one for the one you listed.

I get this above error and also when i type sales or showsalesSummary , nothing happens

~
Regards,

Sinema
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 19, 2003 5:58 pm   
 
Oops, I forgot the variable. It should be:
#LOOPDB @moneySpent {#SH %key bought %val coins.}

For the first of the other formats that you posted, if you are not sure if it may have a comma or not, just include it in the *. The pattern would then be:
*~> (%w) bought the item of * worth (%d) coins.

For the last part of the second format, use ~ before the parenthesis. The pattern would then be:
*~> (%w) paid (%d) gold coins at ~(*~).

You may also use only one trigger and include all three formats with this pattern:
*~> (%w) {bought|paid}*(%d) {coins|gold coins}

and leave out the rest since it is not important. You can find more information about this in Pattern Matching help topic.

Kjata
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