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


Joined: 14 Jun 2006
Posts: 12

PostPosted: Thu Aug 17, 2006 4:33 pm   

Data record search/display
 
Hi,

I have a data record looking something like name|guild|name|guild|name|guild|name|guild

I am trying to expand and display the list according to input. For example:
Mike|Priest|Michael|Witch|Michi|Priest|Michelle|Occultist

Now I want an alias that greps the names with priest in it.
I tried creating an alias using loop, forall however it always comes out with the entire variable.
as examples ive tried using:
#loop @guildList {show %i}
#IF %ismember( %i, @guildList) {#show %i}

However without any success :)

want I want it to display is Priest: Mike, Michi

Thanks for any response in advance.

/B
Reply with quote
saet
Apprentice


Joined: 12 Jun 2006
Posts: 106

PostPosted: Thu Aug 17, 2006 5:53 pm   
 
use #LOOPDB, %key will be the name, %val will be the guild. Could probably be done nicer than this, but this works.

#ALIAS guild {
guildDisplay = ""
#LOOPDB @guildList {
#IF (%val = %proper( %1)) {#IF (@guildDisplay = "") {guildDisplay = %concat( %val, ": ", %key)} {guildDisplay = %concat( @guildDisplay, ", ", %key)}}
}
#SHOW @guildDisplay
}

usage: guild <guildname>

>guild priest
Priest: Suzy, Simon
Reply with quote
Belial
Beginner


Joined: 14 Jun 2006
Posts: 12

PostPosted: Thu Aug 17, 2006 6:33 pm   
 
Ni Saet,

Thanks for your quick response.. I played around a little with what you posted. If I do guild Priest (or priest) it shows the players but not the guild. Result came out:

>guild priest
, Suzy, Simon

I changed the #show command from .
Code:
 #SHOW @guildDisplay

to
Code:
#SHOW %1: @guildDisplay

and its working.
However I see it as a work around to what you posted and would like to learn a more "correct" way of doing it but I cant seem to figure it out.

Thanks
Reply with quote
saet
Apprentice


Joined: 12 Jun 2006
Posts: 106

PostPosted: Thu Aug 17, 2006 8:46 pm   
 
Problem seems to be that #IF (@guildDisplay = "") is not evaluating as true, so it's not putting the Priest: firstname in there. It's just doing the ", name" the first time. Are there maybe some spaces between the quotes?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Aug 17, 2006 11:29 pm   
 
I think what you are looking for is a way to reverse a record variable. A little playing around and this is what I came up with. Assuming test1 as a source variable and test2 as the destination.

#VAR test2 {}
#EXEC {%subchar(%subregex(%expanddb(@test1,"|","="),"(\a+)=(\a+)","#ADDKEY test2 {%2} {!concat(!db(^test2,%2),`,%1)}"),"!|^","%;@")}
#VAR test2 {%subchar(@test2,"`","|")

That produces a rather nice new record variable that should be close to what you want.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Belial
Beginner


Joined: 14 Jun 2006
Posts: 12

PostPosted: Fri Aug 18, 2006 7:17 am   
 
Thanks for the response Vijilante..

I tried it out but the variable test2 came out empty (I changed the test1 in what you posted to my variable containing the info above - also added the closing after the last variable)

I am quite new to the whole scripting however I think what you wrote is what I am looking for.


Saet: I modified your code a little and using:

Code:

#ALIAS guildlist
{
#var guildDisplay {}
#LOOPDB @listGuild {#IF (%val = %proper( %1)) {#IF (@guildDisplay = "") {guildDisplay = %concat( %val, ": ", %key)} {guildDisplay = %concat( @guildDisplay, ",", %key)}}}
#SHOW @guildDisplay
}


And that made it work. I dont know if there is any diffrence using guildDisplay="" or #var guildDisplay {} (since it should? produce the same result right? However it seemed to have solved the problem...
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