|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Fri Jul 30, 2010 12:42 am
How do you sort a db var? |
Can someone please explain how the heck to sort a database variable now? If I use %sort(@dbvar) and then #loopdb @dbvar {#print {%key : %val}} I get the following:
1 : key=val
2 : key=val
3 : key=val
This is not what I want! I don't want index numbers. I have this variable selected to be sorted alphabetically but it won't. I fill the database variable through triggers and then clear it and fill it again via triggers and so on. When it fills it doesn't sort and I can't figure out how to sort it. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Jul 30, 2010 1:52 am |
I believe the simplest way is to set the sort property for that DB var via the settings editor. But it seems like that's what your doing. Are you saying that after you clear it and repopulate it, it's no longer sorting?
When I tried it in an untitled session that seemed to work. |
|
_________________ Asati di tempari! |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Fri Jul 30, 2010 2:26 pm |
You know what...I got this all wrong. It IS sorting. My mistake. When I look in the editor at the variable the keys are sorted. However, the REAL problem here is when I print out the key:val pairs with #loopdb they do not print sorted...
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Fri Jul 30, 2010 2:28 pm |
They also do not print out sorted with #showdb @varList even though the keys ARE actually sorted when I look in the editor. Any reason why?
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Jul 30, 2010 4:00 pm |
I still couldn't reproduce this in a blank session. How are you building your @varList? is that just the list of keys? Here's the code I used as a test.
I created a variable foo and set it as sorted in the settings editor. I then ran the test alias.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="test" language="Lua" copy="yes">
<value>#addkey foo foo goo
#addkey foo boo doo
#addkey foo soo eoo
#addkey foo moo foo
#addkey foo zoo goo
#addkey foo loo hoo
#addkey foo koo ioo
#VAR
#SHOW @foo
#SHOWdb @foo
#SHOW %dbkeys(@foo)
#loopdb @foo {#show %key "=" %val}</value>
</alias>
</cmud>
|
|
|
_________________ Asati di tempari! |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jul 30, 2010 4:54 pm |
The problem is that the %sort(@dbvar) function does NOT sort the @dbvar. It only returns a NEW sorted list. If you actually want to sort the @dbvar itself, you need to use the #SORT command:
#SORT dbvar
and that is equivalent to clicking the Sort checkbox in the editor. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Fri Jul 30, 2010 5:17 pm |
Well now I look like an idiot. It is NOT sorting. I swear I looked in the editor and it was sorted. In fact here is what it looks like right now:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="enemyLocations" type="Record" sorted="1" usedef="true" copy="yes">
<value>Iseria=Observation alcove|Xadzia=The Shaman's Rattle|Katoreos=The Mall of Carnage|Ruthia=Parade of Zarathustra before Main|Crythril=A luxurious riverside estate|Jaisiane=Passing the great shipyards of Sh|Gaetano=Entry to the Merchant's Quarter|Asmodron=The Crossroads|Vrah=The study of the Vicars|Inc=The Shaman's Rattle|Priyer=The Crossroads|Taraza=On the clouds|Aitox=The study of the Vicars|Baudoin=Centre Crossing|Sabiru=On the clouds|Waylon=The Pillars of Ashtan|Karst=Road through a park|Curt=Camp leader's quarters|Terra=A cavern of noxious fumes|Mizik=Atop a high subterranean ledge|Anarwaen=The Shaman's Rattle|Kinley=(house) A dark, shadowy den|Musicia=A luxurious riverside estate|Holinthal=Tundra</value>
<json>{"Asmodron":"The Crossroads","Aitox":"The study of the Vicars","Inc":"The Shaman's Rattle","Xadzia":"The Shaman's Rattle","Baudoin":"Centre Crossing","Jaisiane":"Passing the great shipyards of Sh","Holinthal":"Tundra","Mizik":"Atop a high subterranean ledge","Anarwaen":"The Shaman's Rattle","Karst":"Road through a park","Taraza":"On the clouds","Crythril":"A luxurious riverside estate","Waylon":"The Pillars of Ashtan","Gaetano":"Entry to the Merchant's Quarter","Musicia":"A luxurious riverside estate","Priyer":"The Crossroads","Sabiru":"On the clouds","Iseria":"Observation alcove","Kinley":"(house) A dark, shadowy den","Ruthia":"Parade of Zarathustra before Main","Katoreos":"The Mall of Carnage","Terra":"A cavern of noxious fumes","Vrah":"The study of the Vicars","Curt":"Camp leader's quarters"}</json>
</var>
</cmud> |
All that is in the trigger to add these names and locations is:
Code: |
#addkey enemyLocations %1 %2 |
|
|
|
|
|
|