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


Joined: 28 Sep 2004
Posts: 2

PostPosted: Tue Sep 28, 2004 7:35 pm   

counting dupes in a string
 
Being a stats nerd I want to keep track of mobs killed.

Its easy enough to stick mob names in a string after each kill:

#TRIG ^(*) is dead! R.I.P.
#VAR total_kills_name %additem( %1 %2 %3 , @total_kills_name)

Which gives me: {a minotaur guard|a minotaur guard|a stirge}

My ultimate goal is to count the occurences of each kill, so I get
a modified list to send in tells or #show.

#show a minotaur guard 2
#show a stirge

How can I do this? is there a easier way than a string list?

Thanks!
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Tue Sep 28, 2004 7:41 pm   
 
You might want to consider:

countlist

Syntax: [blue]%countlist[/blue](list)

Count the number of times each item appears in a string list and return a database record with the items as key properties, and the count of each item as the value of the key.
Examples:

#VAR ToDo {kill orc|kill goblin|kill orc}
#VAR ToDo %countlist(@ToDo)
#LOOPDB @ToDo {#SHOW %key %val}

displays:

kill orc 2
kill goblin 1


Last edited by TonDiening on Tue Sep 28, 2004 7:51 pm; edited 1 time in total
Reply with quote
darkspot
Apprentice


Joined: 29 Jul 2002
Posts: 105

PostPosted: Tue Sep 28, 2004 7:44 pm   
 
An alias would work
So you can keep counting with your list I have to make a separate list, I just picked ShowKillsList

#alias Showkills {#var ShowKillsList {%expanddb( %countlist( @total_kills_name), |, ",")};#forall @ShowKillsList {#show %i}}

This will count the list, put it in the ShowKillsList Variable, then show each entry in the list.
This also leaves your Variable @total_kills_name unchanged, so you can keep adding to it.

And if you want them alphabetized also it would be this instead.
#alias Showkills {#var ShowKillsList {%expanddb( %countlist( %sort(@total_kills_name)), |, ",")};#forall @ShowKillsList {#show %i}}

Credit to LightBulb who helped me with this:
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=17501

which was basically the same thing

Might be overcomplicated for what you want though
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Sep 29, 2004 1:00 am   
 
I'd recommend just using a record variable, so the count for each name is already figured. If you want to include your existing counts, use the %countlist function to create the variable.
#VAR total_kills_name %countlist( @total_kills_name)
#TR {^(*) is dead! R.I.P.} {#ADDK total_kills_name {%1} {%eval( %db( @total_kills_name, "%1") + 1)}}

Display or tell can easily be done with the %expanddb function.
#SHOW %expanddb( @total_kills_name)
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
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