Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
kkerwin
Beginner


Joined: 19 Jun 2007
Posts: 23

PostPosted: Sun Aug 05, 2007 4:26 am   

Problems Looping Through Database Variables
 
I'm having difficulty looping through database variables. I have two databases: the values of the first are the keys to the second, as shown below.

Code:

#VAR db_one {}
#ADDKEY db_one key_A valueA
#ADDKEY db_one key_B valueB
#ADDKEY db_one key_C valueC

#VAR db_two {}
#ADDKEY db_two valueA someother_A
#ADDKEY db_two valueB someother_B
#ADDKEY db_two valueC someother_C


This allows me to perform these lookups:

Code:

#SHOW %db(@db_two, %db(@db_one, key_A))
#SHOW %db(@db_two, %db(@db_one, key_B))
#SHOW %db(@db_two, %db(@db_one, key_C))


which return as would be expected:

Code:

someother_A
someother_B
someother_C


However, when I attempt to run it as such,

Code:

#LOOPDB @db_one {
   #SHOW %db(@db_two, %val)
   }


It does not work, producing only newline characters.

Please, what am I doing wrong, and what can I do to remedy the problem? Thanks.
Reply with quote
Arlie
Wanderer


Joined: 09 Jun 2006
Posts: 62
Location: Florida

PostPosted: Sun Aug 05, 2007 7:48 am   
 
I can't actually reproduce this, I'm getting the correct output when following basically the same steps you followed.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sun Aug 05, 2007 11:59 am   
 
First off, I too ran this exactly as you show above and it worked perfectly for me.

I'm guessing that you did not try this on a blank session but instead recreated one of your existing scenarios that is not working for you, which makes sense.

So to start do the obvious and check for typos. Sorry, I use this same type structure in my stuff and I haven't seen the like EXCEPT when there were typos or the second list was empty.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
kkerwin
Beginner


Joined: 19 Jun 2007
Posts: 23

PostPosted: Sun Aug 05, 2007 4:12 pm   
 
Ok, to describe the problem a little further, I've tried the following:


Code:

#LOOPDB @db_one {#echo %db(@db_one, %key)}
#LOOPDB @db_one {#echo %db(@db_two, %val)}

which both produce nothing,

Code:

#LOOPDB @db_one {#echo %val}

which produces

Code:

valueA
valueB
valueC

and finally

Code:

#LOOPDB @db_one {#echo %key}

which produces

Code:

key_A
key_B
key_C

So ... to summarize, I seem to be able to echo the %key and %val outright, but I can't expand either the first or second database records with them when evaluating over a loop. The same problem happens when I have the keys or values stored in a list and loop through the list with the #FORALL command: I can't open another database within the loop.
Reply with quote
kkerwin
Beginner


Joined: 19 Jun 2007
Posts: 23

PostPosted: Sun Aug 05, 2007 4:14 pm   
 
Hmm, something else interesting:

Code:

#LOOPDB @db_one {#echo %db(@db_two, valueA)}

produces

Code:

someother_A
someother_A
someother_A

However, when I try to run it like this:

Code:

#LOOPDB @db_one {#echo %db(@db_two, %val)}

With the literal valueA replaced by the %val in order to loop through the @db_one values, it produces only three newline characters. Is the %val getting confused between the two database records that I'm dealing with somehow? Like: I'm intending for the @db_one values to be used as keys to @db_two. Instead, could it be that the @db_two values are being used as keys to @db_two? If so, how can I be explicit in which values I want evaluated where?

Thanks again.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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