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
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Tue May 18, 2010 1:08 pm   

Numbering the values of a Database Record in sequence.
 
I've been playing around with database records a bit this morning and have become stumped. I have one db record that I am using to populate a second. Then in the second I have one key assigned a value of 1 randomly.

Code:

|   Key  |   Value  |
|    A   |          |
|    B   |          |
|    C   |     1    |
|    D   |          |
|    E   |          |
|    F   |          |


In this example I'm looking for a way to make the value of D 2, E 3, F 4, A 5, B 6 with a single alias if possible. I would also like to be able to have the number of keys be flexible if possible and allow for the 1 to be assigned to any of the keys. Can anyone think of a good way to do this? I figured I'd ask while I give my eyes and brain a rest for a little bit.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue May 18, 2010 2:42 pm   
 
Let me see if I understand the question.

First you want the alias to be able to create a database record with any number of keys.

Then you want to randomly assign the values of those keys to be between 1 and the number of keys?

Code:
#alias createDB {$numlist="";#loop (%int(%1)) {#additem $numlist %i};#loop (%int(%1)) {$rnum=%random(1,%numitems($numlist));$charN=(64+%i);#addkey Rdb %char($charN) %item($numlist,$rnum );#delnitem $numlist $rnum}}


To use it just type createDB [Number] for example [createDB 5].

This particular script does capital letters only so please just use numbers 1-26.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Tue May 18, 2010 3:01 pm   
 
I just used the capital letters as an example the actual keys will be names of player. The keys will already be set in the record with one of them C in the example i posted having a value of 1 already. The key value of 1 will already be randomly assigned to one of the keys already in the record. From there I would like to go down the list and continue numbering the records in order (as they appear in the record). At the end of the list I would like to go back to the top of the record and continue numbering till i reach the key with a value already set to 1. Sorry about that I guess the letters and the way I worded things were kind of misleading.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue May 18, 2010 7:25 pm   
 
I can come up with a method of doing what you ask, but I suspect that if I knew what the purpose of this was I could suggest an even better method of achieving your real goal. One problem is that database variables do _not_ have a guaranteed order of elements. They are actually a hash table, not an ordered list like a stringlist. We could come up with a workaround, but why do you want these records numbered in this way?
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue May 18, 2010 7:53 pm   
 
That and, well Zugg is making a new dataset for Cmud that WILL preserve creation order. Why go to the trouble when it possibly will not be needed within a few days?
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Wed May 19, 2010 1:23 pm   
 
This is for a poker script i'm working on to help pass the time when things are slow for us. I'll put it on the back burner till the new dataset is done and see what I can do then. Thanks.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed May 19, 2010 2:20 pm   
 
You may not need to wait for it, if you explain what exactly you want to do with this data. What I suspect you actually want is to select a "first" element, and then proceed through the remaining elements, in order. I can think of better ways to do that which don't involve database variables. So, what exactly are you trying to do?
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