|
rajasetan Beginner
Joined: 14 Sep 2006 Posts: 11 Location: Jakarta, Indonesia
|
Posted: Mon Oct 09, 2006 4:45 am
Help Extracting Values from Data Record Variable |
Hi,
Can anyone help me with how to extract all same values in a data record variable?
I'm planning to use a data record variable called "enemies", with names as the keys and an "in" or "out" as values to indicate whether or not they're online.
I can get they're online status from a who command sent to the mud and get the "in" values.
Problem is that the who list from the mud is quite long and shows names in random positions.
What I want is to make an alias that will only show those from the "enemies" variable who is (has the value) "in".
Can anyone please help? Thanks! |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Oct 09, 2006 10:51 am |
You can try to modify my relatively generic data record reversal. I only ever tested the #EXEC portion on the command line, so it will likely need a few things to work properly in an alias.
#ALIAS DataRecordReversal {#EXEC {%subchar(%subregex(%expanddb(@test1,"|","="),"(\a+)=(\a+)","#ADDKEY test2 {%2} {!concat(!db($test2,%2),`,%1)}"),"!|$","%~;@")}} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
rajasetan Beginner
Joined: 14 Sep 2006 Posts: 11 Location: Jakarta, Indonesia
|
Posted: Mon Oct 09, 2006 6:00 pm |
Thanks for the reply, Vijilante.
I'm afraid the code you gave me is still too advanced for me to understand. Can you explain it? Thanks.
And here's an example for a clearer picture of what I'm trying to do.
I have a variable called "enemies" storing enemy names, looking something like:
{Enemy1=0|Enemy2=0|Enemy3=0|Enemy4=0|Enemy5=0}
Requesting a brief who list from the mud, it gives:
Enemy1, personX, personM, Enemy5, personY, Enemy3, Enemy4, personJ, personF
, personH, mycharacter.
I triggered this output to adjust the variable to:
{Enemy1=1|Enemy2=0|Enemy3=1|Enemy4=1|Enemy5=1}
Now (this is where i'm stuck) I want to make an alias that can show me:
Enemies Online: Enemy1, Enemy3, Enemy4, Enemy5
Thanks! |
|
|
|
Full Throttle Wanderer
Joined: 07 Dec 2004 Posts: 65
|
Posted: Wed Oct 11, 2006 3:45 am |
#var enemy_list {EA|EB|EC|ED|EE}
#var player_online {EB|PA|PB|EC|PC|EE|YOU}
#var enemy_online %delitem("YOU",@player_online)
#forall @enemy_online {#if !(%ismember(%i,@enemy_list)) {#var enemy_online %delitem(%i,@enemy_online)}}
#show Enemies Online: %expandlist(@enemy_online,", ")
Enemies Online: EB, EC, EE |
|
|
|
rajasetan Beginner
Joined: 14 Sep 2006 Posts: 11 Location: Jakarta, Indonesia
|
Posted: Thu Oct 12, 2006 5:50 am |
Thanks Full Throttle,
I was too fixed on using data record vars that I forgot it can be achieved through a different method.
But I would still like to know how to achieve it using data record variable |
|
|
|
Full Throttle Wanderer
Joined: 07 Dec 2004 Posts: 65
|
Posted: Thu Oct 12, 2006 4:37 pm |
add a second forall to above code if you wish to sort enemy_online in order of enemy_list
#forall @enemy_list {#if %ismember(%i,@enemy_online) {
#var enemy_online %delitem(%i,@enemy_online)
#var enemy_online %additem(%i,@enemy_online)}}
using a database variable
#addkey enemy_db {EA=0|EB=0|EC=0|ED=0|EE=0}
#var player_online {EB|PA|PB|EC|PC|EE|YOU}
#forall @player_online {#if %iskey(@enemy_db,%i) {#addkey enemy_db %i 1}}
#showdb @enemy_db
EA: 0
EB: 1
EC: 1
ED: 0
EE: 1
#loopdb @enemy_db {#if (%db(@enemy_db,%key) = 0) {#delkey enemy_db %key}}
#show Enemies Online: %expanddb(%subregex(@enemy_db,".1",""),", ","")
Enemies Online: EB, EC, EE |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu Oct 12, 2006 10:53 pm |
The fastest way to actually do all of this is right at the time of the capture. Right now you have a list of enemies and when you capture the right texts you compare to that list then use #ADDKEY to set the online status for that enemy, you should also set them into your other list at the same time. Essentially you have spent a large portion of your script's time building and resetting the wrong type of variable. I am not going to really expound upon the snippet I posted since it was meant for restructuring data when there is no way to really store it by other means. It would take many tweaks to work with what you have, and you have better options available. You should certainely make use of those other options; but keep the little snippet in the back of your mind for when you know how to modify it yourself and when it is really needed.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
rajasetan Beginner
Joined: 14 Sep 2006 Posts: 11 Location: Jakarta, Indonesia
|
Posted: Sat Oct 14, 2006 9:43 am |
Thanks again! Doing it all at the capturing time sounds like a good idea too.
|
|
|
|
|
|
|
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
|
|