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


Joined: 16 Dec 2007
Posts: 3

PostPosted: Sun Dec 16, 2007 12:14 pm   

database record UNsorting
 
Sorry if this is a stupid question, but after upgrading to 2.18 I had the problem that all my db records were suddenly sorted either in ascending order (if I checked the sort button) or descending order (if the button is unchecked). Each time I hit save it would sort them.

For my scripts I simply need the keys and values sorted in the order I put them in (or in other words pretty much unsorted). Any idea how I can get that back?

EDIT: I just noticed, it's not -always- descending order if the sort button is not checked, although most often it is. The fact remains though that it -always- with or without checked sort button resorts the keys/values I put in. I'd like them to simply remain in exactly the order I put them in though..


Last edited by Asrai on Sun Dec 16, 2007 12:49 pm; edited 1 time in total
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Sun Dec 16, 2007 12:46 pm   
 
I am having problems with variables too. It seems the editor tries to "help" you and then shoots itself, you and everyone around in the foot instead.

In my case I was trying to maintain a string-list of sentences that should be highlighted in a certain color. This used to work nicely, but after upgrading from 1.x I find that certain characters will mess things up when saving. For instance it didn't like the character " very much. If I tried to make the to strings below it would put them together as one entry in the string list looking something like the last line. I haven't solved the problem - just worked around it. *sighs*

tells you, "
You say, "

tells you, "|"You say, "
Reply with quote
Malach
Apprentice


Joined: 03 Nov 2007
Posts: 132

PostPosted: Sun Dec 16, 2007 2:17 pm   
 
About the sorting, here is what Zugg has said on that:

quote="Zugg"]About the order of database variables...How were you accessing the database variable? Using #SHOWDB and #LOOPDB, the order is undefined (it is based upon the internal hash table). This is true in most all languages that support database variables (or associative arrays), such as Perl and PHP.

If you want to loop through a database by key creation order, you can use this:
Code:
#loop %numitems(@db) {$key=%item(@db,%i);#show {$key = %db(@db,$key)}}

The %item function returns the "nth key" in a database and does this based upon creation order and not hash order.

If you want to loop through a database by alphabetical key order, you can use this:
Code:
#forall %sort(%dbkeys(@db)) {#show {%i = %db(@db,%i)}}
[/quote]
_________________
Intel Core2 Quad CPU @ 2.4 GHZ with Windows Vista Home Premium and 2 GB Ram
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sun Dec 16, 2007 2:34 pm   Re: database record UNsorting
 
Asrai wrote:
Sorry if this is a stupid question, but after upgrading to 2.18 I had the problem that all my db records were suddenly sorted either in ascending order (if I checked the sort button) or descending order (if the button is unchecked). Each time I hit save it would sort them.

For my scripts I simply need the keys and values sorted in the order I put them in (or in other words pretty much unsorted). Any idea how I can get that back?

EDIT: I just noticed, it's not -always- descending order if the sort button is not checked, although most often it is. The fact remains though that it -always- with or without checked sort button resorts the keys/values I put in. I'd like them to simply remain in exactly the order I put them in though..

Zugg has optimized the db records. At version 2.00 in the changelog it says: "New hash tables for string lists and database record variables provides a huge speed boost". Perhaps that's what cause the sorting?
Reply with quote
Asrai
Newbie


Joined: 16 Dec 2007
Posts: 3

PostPosted: Sun Dec 16, 2007 2:38 pm   
 
Key creation order is more or less what I want. I tried the loop you suggested but the output I get is still very much random and definitely not the order in which I created the items (I even tried to create them with #addkey to make sure). If I leave the sort button unchecked it seems to show it in the order that the editor does too..

EDIT: this is what I used:

alias:
Code:

#var testdb %null
#addkey testdb keyone valone
#addkey testdb keytwo valtwo
#addkey testdb keythree valthree
#loop %numitems(@testdb) {$key=%item(@testdb,%i);#show {$key = %db(@testdb,$key)}}


The output I got was this however:

keytwo = valtwo
keythree = valthree
keyone = valone

At least it's consistently the same but still not what I was looking for. :/
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Dec 16, 2007 2:55 pm   
 
If you care about the order of keys, you probably shouldn't be using a data record variable. Like Zugg says, it's common to many languages that the hashing gives them arbitrary order, and shouldn't be surprising.

The idea of a data record is that you refer to an item by its key, and that you needn't know its relative position. The idea of a stringlist is that you refer to an item by its relative position. Generally you need only one or the other. If we knew more about what you were trying to do with them, we could perhaps offer you another solution.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Asrai
Newbie


Joined: 16 Dec 2007
Posts: 3

PostPosted: Sun Dec 16, 2007 4:07 pm   
 
Well, I had it basically set up that the key defined the action and the value the item to use. Depending on what ritual it was doing the order of the actions (and the actions themselves) as well as the items could all vary. I've found a way to work around it now with an additional string list that defines the order for the actions. My main issue was that I -really- didn't want to rewrite the entire thing. Thanks for the help. :)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 17, 2007 6:24 pm   
 
Kjaerhus, it sounds like you have a different problem. Could you make a new post with some more details so we can help you?
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