Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Fri Mar 28, 2008 3:14 pm   

Sorting DB by %val
 
Is this possible?
Background::
During special events, the mud assigns 10-15 mobs and gives the zone they are in with the name
I currently have a capture script that sends them to another window.. Makes it easier to manage.
What i'd like to do is to be able to sort the DB by the %val or %key, either would be fine.
But reading other notes it ddoesnt appear to be possible
I tried #sort @DB, but appeared to not do anything.. Suggestions?
Code:

#addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
#addkey CPMobs {%2} {%1}
#show @CPMobs

Thats the Value for the trigger that loads the info to the DB.. The #show is purely for Testing purposes..
What i noticed was that one of the mobs was colored.. And it caused the script to empty and start new.. No idea why this would happen..
unless it was trying to copy that colorcode which i dont see why it would..
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Mar 28, 2008 4:00 pm   
 
Hrm...sorting by keys is pretty straightforward:
Code:
dbv=""
#addkey dbv a z
#addkey dbv c x
#addkey dbv b y
#addkey dbv g h
#addkey dbv f i
#addkey dbv d q
#show %sort(@dbv)

gives me
Code:
a=z|b=y|c=x|d=q|f=i|g=h

Sorted by keys. And, to be honest, it looks like the #addkey code keeps it sorted by keys in the first place, so %sort() isn't even necessary. However, even if you just cram an unsorted record-like stringlist in there, the %sort call still does what you want:
Code:
dbv="c=x|a=z|b=y|d=q"
#show %db(@dbv,c) @dbv.a // just to prove that you can access this like a DB var
#show %sort(@dbv)

gives
Code:
x z
a=z|b=y|c=x|d=q

Now, sorting by VALUES is a different matter. IMHO, it's usually easier to just arrange things so that the keys are the things you want to sort on, or even to rebuild a new DB with the keys and values reversed:
Code:
dbv=""
#addkey dbv a z
#addkey dbv c x
#addkey dbv b y
#addkey dbv d x // Note that we have a duplicate
dbs="" // we'll rebuild this one for our sort, with keys/vals reversed
#forall %dbkeys(@dbv) {$key=%i;$val=%db(@dbv,$key);dbs.$val=%additem($key,@dbs.$val)}
#show %sort(@dbs)

gives
Code:
x="c|d"|y=b|z=a
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!

Last edited by JQuilici on Fri Mar 28, 2008 4:07 pm; edited 1 time in total
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Mar 28, 2008 4:06 pm   Re: Sorting DB by %val
 
jtown84 wrote:
Code:

#addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
#addkey CPMobs {%2} {%1}
#show @CPMobs

Thats the Value for the trigger that loads the info to the DB.. The #show is purely for Testing purposes..
What i noticed was that one of the mobs was colored.. And it caused the script to empty and start new.. No idea why this would happen..
unless it was trying to copy that colorcode which i dont see why it would..

My earlier reply came before you edited the original post to include this info.

I'm not sure what you mean by 'caused the script to empty and start new'. Can you post the MUD output and the full XML of your trigger, please?
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Fri Mar 28, 2008 4:10 pm   
 
Just To show you What is going on.
Quote:

You still have to kill * A skittish deer (Realm of the Zodiac)
You still have to kill * grey skies (Fantasy Fields)
You still have to kill * The statue of Seth (New Thalos)
You still have to kill * The Prodigal Sorcerer (The Land of Dominia)
You still have to kill * the Priestess of Ofcol (The Town of New Ofcol)
You still have to kill * Dr Ulamnonon (Canyon Memorial Hospital)
You still have to kill * A nightmare (Kul Tiras)
You still have to kill * The Rock Hydra's Head (The Land of Dominia)
You still have to kill * a Worshipper (Ancient Greece)

That is what the mud sends.. (The words in () are area names)

What i've done is
Code:
^You still have to kill ~* (*) ~((*)~)$

Code:
#addkey CPMobs {%2} {%1}
Note that it adds Area as the %key now.
One of the problems i'm having is running from one area, to the next then back to area a, for instance Land of Dominia in this example
the DB Var that i end up with is..
Code:

Realm of the Zodiac=A skittish deer|Canyon Memorial Hospital=Dr Ulamnonon|Kul Tiras=A nightmare|Ancient Greece=a Worshipper|The Land of Dominia=The Rock Hydra's Head|New Thalos=The statue of Seth|The Town of New Ofcol=the Priestess of Ofcol|Fantasy Fields=grey skies

And while posting this.. I noticed another problem, By sorting by area name if there is 2 of the mobs in the list with the same area.. it will erase prior key, Which i dont want happening.. I thought about going with a string list, but would be very difficult to keep the mob/area together if i did that.



edit: The problem earlier was my mistake, it was creating the %key 2x so erasing the first one, it just happened to be that the mob was in color
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Mar 28, 2008 4:52 pm   
 
jtown84 wrote:
What i've done is
Code:
^You still have to kill ~* (*) ~((*)~)$

Code:
#addkey CPMobs {%2} {%1}
Note that it adds Area as the %key now.
One of the problems i'm having is running from one area, to the next then back to area a, for instance Land of Dominia in this example
the DB Var that i end up with is..
Code:

Realm of the Zodiac=A skittish deer|Canyon Memorial Hospital=Dr Ulamnonon|Kul Tiras=A nightmare|Ancient Greece=a Worshipper|The Land of Dominia=The Rock Hydra's Head|New Thalos=The statue of Seth|The Town of New Ofcol=the Priestess of Ofcol|Fantasy Fields=grey skies

And while posting this.. I noticed another problem, By sorting by area name if there is 2 of the mobs in the list with the same area.. it will erase prior key, Which i dont want happening.. I thought about going with a string list, but would be very difficult to keep the mob/area together if i did that.

This maps pretty closely to the second set of code I did, above. Use %additem to keep stringlists inside the DB variable.

To be more specific, I think the following trigger is what you want:
Code:
#TRIG {^You still have to kill ~* (*) ~((*)~)$} {CPMobs.%2=%additem(%1,@CPMobs.%2)}

Then CPMobs will have a bunch of fields. Each key is a zone, and the value is a stringlist of the mobs in that zone. For instance, tested against your sample output, CPMobs would be (as shown by '#show %sort(@CPMobs)'):
Code:
Canyon Memorial Hospital=Dr Ulamnonon|Fantasy Fields=grey skies|Kul Tiras=A nightmare|New Thalos=The statue of Seth|Realm of the Zodiac=A skittish deer|The Land of Dominia="The Prodigal Sorcerer|The Rock Hydra's Head"|The Town of New Ofcol=the Priestess of Ofcol

Note that the Land of Dominia has TWO mobs in it, in a stringlist.
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Mar 28, 2008 5:13 pm   
 
The only thing I would add to that JQuilici is a %dups to the value returned from the additem so each mob only gets added once
Code:
#addkey CPMobs {%2} {%dups(%additem(%1,%db(@CPMobs,%2)))}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Mar 28, 2008 5:23 pm   
 
I'm betting that he would want to preserve that info. If the instructions included a mob in that zone twice, he probably has to kill two of them. Wink
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Sat Mar 29, 2008 7:17 am   
 
Well now that i officially suck at scripting..
Code:
#window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%1%ansi(red)~] ~[%ansi(high,White)%2%ansi(red)~]}

That was in the trigger to capture the mobs in another window..
All i really want to do is %sort it
I just have 0 idea how to go about it.. I honestly feel dumb.

edit:
What i have now is..
Code:
#loopdb @CPMobs {#window CP_GQ {%ansi(red)~[%ansi(white)%key %ansi(red)~] ~[%ansi(high,White)%val %ansi(red)~]}}

and what it returns is..
Quote:
[The Coral Kingdom ] [a slave guard ]
[The Silver Volcano ] [an owl ]
[Ancient Greece ] [the Judge ]
[The Land of Dominia ] [The Elder Spawn ]
[Death's Manor ] [Ereshkigal ]
[Doom and Gloom ] [a Hell Knight ]
[Jungles of Verume ] [Tabaxi child|A wise lizardman ]
[Kingdom of Ahner ] [Dullurd soldier|Eduardo the stable boy ]
[Cradlebrook ] [a pheasant ]
[The Mirror Realm ] [the unicorn ]
[The Labyrinth ] [a violet fungus ]

It seperates the Mobs by a pipe, Which is Great for me
But when i distro this.. I am not sure if others will understand it.
Is it possible to sort the list and have
Quote:
[Jungles of Verume ] [Tabaxi child]
[Jungles of Verume ] [A wise lizardman ]

or something like that.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Mar 29, 2008 9:57 am   
 
Code:
#loopdb @CPMobs {#loop %numitems(%val) {#window CP_GQ {%ansi(red)~[%ansi(white)%key %ansi(red)~] ~[%ansi(high,White)%item(%val,%i) %ansi(red)~]} }}

_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Sat Mar 29, 2008 1:31 pm   
 
I'm simply amazed at how much i still dont know.. Thanks.

Code:
#loopdb @CPMobs {
#addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
#loop %numitems(%val) {#window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%key %ansi(red)~] ~[%ansi(high,White)%item(%val,%i) %ansi(red)~]}}}

And it works fine, except the sort.. Any ideas?
Quote:
1. [The Coral Kingdom ] [a slave guard ]
2. [The Silver Volcano ] [an owl ]
3. [Ancient Greece ] [the Judge ]
4. [The Land of Dominia ] [The Elder Spawn ]
5. [Death's Manor ] [Ereshkigal ]
6. [Doom and Gloom ] [a Hell Knight ]
7. [Jungles of Verume ] [A wise lizardman ]
8. [Kingdom of Ahner ] [Dullurd soldier ]
8. [Kingdom of Ahner ] [Eduardo the stable boy ]
9. [Cradlebrook ] [a pheasant ]
10. [The Mirror Realm ] [the unicorn ]
11. [The Labyrinth ] [a violet fungus ]

Is current turnout
_________________
Aardwolf
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Mar 29, 2008 4:49 pm   
 
This will sort alphabetically by Area and within each Area by Mobname.
Code:
#for %sort(%dbkeys(@CPMobs)) {
  #addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
  #for %sort(@CPMobs.%i)  {
    #window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%i %ansi(red)~] ~[%ansi(high,White)%j %ansi(red)~]}
  }
}






I noticed the numbers at the beginning only increment with each area.
If you want it to go up with each line just move the line with #addkey CapDB CPMobNumber
to the inner loop. ala:

Code:
#for %sort(%dbkeys(@CPMobs)) { 
  #for %sort(@CPMobs.%i)  {
  #addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
    #window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%i %ansi(red)~] ~[%ansi(high,White)%j %ansi(red)~]}
  }
}
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Sat Mar 29, 2008 5:25 pm   
 
Yes. AFAIK, the #LOOPDB command doesn't sort the keys - it just interates through them in whatever order they pop out of the hash table. So we need to sort the keys manually, then get the values to correspond:
Code:
#ALIAS ShowMobs {
  $mobNum=0
  #FORALL %sort(%dbkeys(@CPMobs)) {
    #FORALL %sort(@CPMobs.%i) {
      $mobNum=$mobNum+1
      #window CP_GQ {$mobNum~.~[%i~] ~[%j~]}
    }
  }
}

You can add all the ansi colors and your CPMobNumber accounting where appropriate. I got the following in the CP_GQ window (using your test output from before):
Code:
1.[Canyon Memorial Hospital] [Dr Ulamnonon]
2.[Fantasy Fields] [grey skies]
3.[Kul Tiras] [A nightmare]
4.[New Thalos] [The statue of Seth]
5.[Realm of the Zodiac] [A skittish deer]
6.[The Land of Dominia] [The Prodigal Sorcerer]
7.[The Land of Dominia] [The Rock Hydra's Head]
8.[The Town of New Ofcol] [the Priestess of Ofcol ]


EDIT: Ninja'd by Dharkael. Smile
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Sat Mar 29, 2008 7:13 pm   
 
Quote:

Code:
#for %sort(%dbkeys(@CPMobs)) {
#for %sort(@CPMobs.%i) {
#addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
#window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%i %ansi(red)~] ~[%ansi(high,White)%j %ansi(red)~]}
}
}

PERFECTION! I'll have to read helps to figure out how it was done, but i want to say thanks.
_________________
Aardwolf
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Mar 29, 2008 7:56 pm   
 
Crawling the helps is definitely a good way to go.
One thing you wont find in the help is the use of %j for nested #loop/#forall statements
%i is to the outer loop as %j is to the inner loop
it keeps advancing through the alphabet as the loops get nested (I tested it up to n ie 6 nested loops)

Example
Code:
#var outer {o1|o2|o3}
#var inner {i1|i2}
#forall @outer {
  #forall @inner {
    #echo Outer: %i , Inner: %j
  }
}


Would show
Quote:
Outer: o1 , Inner: i1
Outer: o1 , Inner: i2
Outer: o2 , Inner: i1
Outer: o2 , Inner: i2
Outer: o3 , Inner: i1
Outer: o3 , Inner: i2


Everything else should be in the helps
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Mon Mar 31, 2008 10:22 am   
 
jtown84 wrote:
Quote:

Code:
#for %sort(%dbkeys(@CPMobs)) {
#for %sort(@CPMobs.%i) {
#addkey CapDB CPMobNumber {%eval(@CapDB.CPMobNumber + 1)}
#window CP_GQ {%ansi(high, white)@CapDB.CPMobNumber~. %ansi(red)~[%ansi(white)%i %ansi(red)~] ~[%ansi(high,White)%j %ansi(red)~]}
}
}

PERFECTION! I'll have to read helps to figure out how it was done, but i want to say thanks.

This worked fine for 2 days, and now it broke
i have an alias 'cch' that clears the CPMOBS variable
It stopped working.. I've restarted computer and after doing such it works a few times
If i restart cmud it works once or twice but Always fails..
I exported all settings that relate.. I think
http://www.thegameforums.net/jtowns/Aardwolf/cp%20capture.xml
_________________
Aardwolf
Reply with quote
jtown84
Novice


Joined: 09 Oct 2007
Posts: 36

PostPosted: Mon Mar 31, 2008 10:22 am   
 
edit: fixed.. sorry for being dumb:( duplicated vars somehow
_________________
Aardwolf
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed Apr 16, 2008 12:44 am   
 
I was wondering why you are using ANSI color codes. If you use the <color colorname>....</color> structure within the #WINDOW command, it will work just fine.
_________________
Sic itur ad astra.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed Apr 16, 2008 1:20 am   
 
There is currently at least one drawback with the mxp colour syntax...
It wont get logged properly.
Since he said above that this script was for distrubution, if the ansi colours suffices its probably best that they be used.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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