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


Joined: 08 Feb 2006
Posts: 25

PostPosted: Sun Jun 05, 2011 8:01 am   

Nested Database Records/String lists (Best way?)
 
I found a thread regarding this that basically says its not supported for use with like %iskey etc since CMUD does not hash the nested values so is slow and unsupported

Maybe I read too much into it, but it made me wonder

What would be the best way to implement something like this?

I originally wrote a helper function that would get/set values inside the main @var for me... and it worked 90% of the time... however on 1 of the 3 nested list %iskey returns the wrong index value make it not trustable for future use :/


Thanks!
_________________
-Karl
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Jun 06, 2011 5:13 am   
 
I think this may have changed with the introduction of JSON/GMCP support, since GMCP is basically a series of nested datarecords and stringlists. I JUST spent nearly the entire evening working out the parsing for the GMCP group module data sent by Aardwolf, though, so I'm not entirely sure and I'm too brainhurt to be of much use now.
_________________
EDIT: I didn't like my old signature
Reply with quote
tekky
Beginner


Joined: 08 Feb 2006
Posts: 25

PostPosted: Mon Jun 06, 2011 5:39 am   
 
Interesting... I have a nested var like this....

@actions is the var with keys
action1: prop1=val1|prop2=val2|prop3=val3
action2: prop1=val1|prop2=val2|prop3=val3
action3: prop1=val1|prop2=val2|prop3=val3

props are different for each action (some are the same occassionally) and I have a accessor function I wrote that looks like this

Code:

<func name="action" id="199">
  <value><![CDATA[#local $action $value
#if (%1 && %2 && %iskey(@actions,%1)) {
$action = %item(@actions,%iskey(@actions,%1))
$action = @actions.%1
#show $action
#if (%iskey($action,%2)) {
#show %iskey($action,%2)
$value = %item($action,%iskey($action,%2))
#show $value
#return {$value}
}
}
]]></value>
</func>


using @action(key,subkey) should return the proper value, and #show in the above code returns the proper string list from the @action var however it never fails... 1 of the 3 (action1-3) will return subkeys that are 1 index off (seems it changes based on something... I havent pinned down yet)
_________________
-Karl
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Jun 06, 2011 3:50 pm   
 
Well, you are doing that rather awkwardly. Why are you using %iskey for this? It is much easier to use %db(). Here's an example (untested, I can't test it here at work):
Code:

#LOCAL $action $value

#IF (!%1 OR !%2) {#RETURN}
$action = %db(@actions,%1)
#IF (!$action) {#RETURN}
#SHOW $action

$value = %db($action,%2)
#IF (!$value) {#RETURN}
#SHOW $value
#RETURN {$value}
Reply with quote
tekky
Beginner


Joined: 08 Feb 2006
Posts: 25

PostPosted: Wed Jun 08, 2011 5:21 am   
 
Rahab, %iskey/%item was what I came across in the help files... your %db suggestion actually works... I'll test it out and see if it has any issues but looks like that will solve that problem

Thank you!
_________________
-Karl
Reply with quote
tekky
Beginner


Joined: 08 Feb 2006
Posts: 25

PostPosted: Wed Jun 08, 2011 7:13 am   
 
Just thought you might be interested in seeing my finished goal -- it now becomes a getter/setter so @action(skill,prop) returns the value of @actions.skill.prop and @action(skill,prop,value) sets @actions.skill.prop to value

The idea for this came up after manually setting a value and the skill not existing... it nerf'd the whole var somehow and I had to recreate it... so... this prevents accidental mistakes cause it will create any missing steps in the path :)
(at least its passed my initial tests -- will be pushing it in my code for usage in the next day or so)

Thanks again Rahab for the insight!

Code:

#local $action $value
#if (%numparam() < 2) { #return }
$action = %db(@actions,%param(1))
#if (%numparam() = 3) {
#addkey $action %param(2) %param(3)
#addkey actions %param(1) $action
#return %param(3)
}
$value = %db($action,%param(2))
#if ($value) {
#return {$value}
}
_________________
-Karl
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