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


Joined: 26 Apr 2007
Posts: 29

PostPosted: Wed Mar 26, 2008 12:11 am   

database record - order messing up
 
I have a variable @salve_cures which is a database record. It contains several afflictions which are cured by using a salve. It contains the affliction and the corresponding cure to it.

key | value
=============
anorexia | epidermal to torso
mend2arms | mending to arms
...


The order of the afflictions is very important. But somehow CMUD seems to forgot the order when I save the variable, and comes up with a new one. In the example it put anorexia behind mend2arms. Is this intended? I'm not using the 'Sorted' option, and the new order is not even alfabetic, but seems semi-random. Is there a way to avoid this re-ordering? It used to work fine in zMUD.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Wed Mar 26, 2008 12:31 am   
 
It is not a matter of forgetfulness. The records data is stored in a hash, so that's how it is returned. You'll have to use a scheme to assure that the keys are retreived in some specific order parametrically. One way to avoid that is to add them to one single value in the form %concat(value1," $", value2," ",....valueN), where the "$" is the delimeter. Then retreive the value and decompose the string buy using %word. I have found problems storing string lists in the database even though it is supposed to be a valid procedure now. So I just store a string with the values separated by something distinctive.
_________________
Sic itur ad astra.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Wed Mar 26, 2008 12:38 am   
 
Sadly there isn't anyway to avoid this sort of reordering. In recent versions CMud was changed to use a hash table to speed up the lookup time in list and record variables. The speed increase is generally worth the fact that it no longer maintains the order of the variables.

For your specific problem I have a similar record that I maintain. I inserted numbers at the begining of each key and set the list to sorted. For example
Code:
000-anorexia | epidermal to torso
002-mend2arms | mending to arms
The benefit to me from this is that anorexia actually has a few cures, and I can list it multiple times in the correct place, using different numbers, such that 1 pass through record will cure as many things as possible. The extra speed from both things makes overall curing much faster.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
NitroGlycerine
Beginner


Joined: 26 Apr 2007
Posts: 29

PostPosted: Wed Mar 26, 2008 12:41 am   
 
Ah, thank you.

Does the same apply to String Lists? Or do they keep their order fixed?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Wed Mar 26, 2008 12:54 am   
 
Lists maintain the order in which items were added. Using the #SORT command on them causes them to maintain a sorted order.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Wed Mar 26, 2008 8:14 am   
 
Your value seems a bit uneccesary, too - if mend2arms is an alias or a string that can be passed to a function to get the full cure text, you don't need the value. If it's not, you don't need the key. So a stringlist would work very well for this.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Mar 27, 2008 12:18 am   
 
That is what I suggested, however, as I stated before, I haven't gotten true stringlists to work with records stored in the database. So what I do is just append the values to a string using a consistent delimeter and then extract the values using %word. If in fact, stringlists within stored database records are working, please let me know. I think what the database record needs for this to work properly is a stringlist value type.
_________________
Sic itur ad astra.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Thu Mar 27, 2008 8:36 am   
 
Eh? There's no need at all to use a data record variable in this situation. The OP is using a single data record variable to store his afflictions; I'm suggesting using a stringlist instead. No problems storing stringlists in data record variables.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Mar 27, 2008 11:33 pm   
 
I didn't say that there were problems storing stringlists into database records. I said that there were problems storing database records that contain stringlists into a database. They show up enclosed in quotes, and no longer a stringlist. There is no stringlist value type, so you must assign one of the existing types to the value. Perhaps, that is where my problem stems from. I would be very happy to know which value type I should use.
_________________
Sic itur ad astra.
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