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
Bajed
Novice


Joined: 15 Aug 2004
Posts: 33

PostPosted: Sun Jun 24, 2007 2:11 pm   

How do I access database records by number?
 
I have a database record listing varios things that I want to perform operations on one at a time. Example:

item1 = 5
item4 = 8
item32 = 2

And so on. I don't know the key names of each item though so I want to access them by number instead. is this possible? For example, on the first loop I want to do something to @myRec.1, which is item1/5... after I do this, i want to reduce the number 5 down to 4, and move to the next loop, when the number reaches 0 I'll remove that record from the database and continue, meaning we'd be on item4/8, then item4/7, and so on.

Does this make sense? Heh.

Any help would be appreciated.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Jun 24, 2007 5:52 pm   
 
Using #loopdb you can loop through a db variable. This will expose both the key and the value in the %key and %val predefined variables so that the script contained in this loop structure can act on them.
_________________
EDIT: I didn't like my old signature
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun Jun 24, 2007 11:15 pm   
 
Code:
#loopdb @DBRecord {#noop do something here using %val or whatever;#var DBRecord.%{key} %eval(%number(%val) - 1);#if (%val = 1) {#delk DBRecord %key} {};#abort }


The #abort stops the loop so that you're only ever working on the first key-value pair
_________________
-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