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


Joined: 16 Sep 2008
Posts: 20

PostPosted: Tue Sep 16, 2008 5:09 pm   

Database record question
 
This is probably silly, and listed somewhere, but I can't for the life of me seem to find it anywhere.


Currently converting from zMUD to CMUD, and I've got my code changes worked out for pretty much everything except an issue with database records. Please forgive any incorrect terminology.

In zMUD, you could modify the value of a key like an independent string list. For instance, (#additem database.key value) worked. in CMUD I can get numerical math functions to work on the value, I can add text as a lump ad rewrite it, but can't figure out if/how I can modify text strings. I know I could just use string lists, but the easy modification or even complete deletion and recreation of keys was handy for cross-referencing, without having a large number of string list variables floating around. Not to mention it would be nice to make use of the added database speed increases this way.

Can someone point me to the related commands, preferably with usage examples, or did this go away entirely?

Thanks!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Sep 16, 2008 8:39 pm   
 
#addkey database key value

This existed unde zmud as well.
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Tue Sep 16, 2008 9:11 pm   
 
Unless I'm mistaken, #addkey will replace the key/value completely. I'm looking to modify a text value similarly to a string. The ability to add text in, and pull it back out, without disrupting or even needing to reference the remainder of the value.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Tue Sep 16, 2008 11:02 pm   
 
you can manipulate it as a string, just use the shortcut to the value

%concat(@dbVAR.key, " has been extended")
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Tue Sep 16, 2008 11:09 pm   
 
ahhh string list as the value... this can be donw as well, though you will want to make use of local vars as well

i believe CMUD treats a stringlist value for a DB var as just a string with |'s in it, however if you did something like

$Var=@dbVar.Key

then $var would be the stringlist you wanna manipulate, the way you normally would, then when your done manipulating it

#ADDKEY dbVar key $var
_________________
Discord: Shalimarwildcat
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Tue Sep 16, 2008 11:38 pm   
 
Ahh... perfect, that was the step I was missing.

Odd how you can get the whole "I used to approach it this way...." stuck in your head and sometimes not notice the alternate path.
Was a bit bummed the first time I tried an additem/delitem directly on a value. The workaround has been eluding me for a few days now.

Thanks a lot, Shalimar!
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Wed Sep 17, 2008 4:55 pm   
 
After playing around with the database records a bit more, I've noticed that most commands listed for use with string lists do work on the values of the database record keys. For example, these work and react with the values like they would on string lists, as long as the pipes are in the right places.

#Forall {@database.key}
#Show %numitems(@database.key)
#Show %additem("value",@database.key)
#Show %delitem("value",@database.key)


These seem to be exceptions:

#Additem database.key
#Delitem database.key

Is this intentional, possibly to be released later or maybe even overlooked? I am using ver. 2.36. Just seems odd that most, even %additem/%delitem would work, but not #additem/#delitem.


For a useful example, the following is used in a few places in zMUD to synchronize records.

#loopdb @database1 {#forall {%val} {#if (%iskey(@database2, %i)) {#delitem database1.%key {i}}}

This wouldn't work quite so well with the local variable extraction workaround, I don't think.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Sep 17, 2008 7:35 pm   
 
I don't know whether it is a bug. However, in your #loopdb example from zmud, you could use %delitem().
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Wed Sep 17, 2008 10:06 pm   
 
With the differences in usage and duplicate handling, I've never been able to get %delitem() to work in this instance. Here's exactly the zMUD effect I'm looking to duplicate......

#addkey database1 key {val1|val2|val1|val3}
#addkey database2 {val1=1|val2=1}
#loopdb @database1 {#forall {%val} {#if (%iskey( @database2, %i)) {#delitem database1.%key {%i}}}}
#show @database1.key

This shows "val3" in zMUD, and "val1|val2|val1|val3" in CMUD.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Thu Sep 18, 2008 1:16 am   
 
does it work when you define it to a local var?
_________________
Discord: Shalimarwildcat
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Thu Sep 18, 2008 2:32 am   
 
Not that I can figure out. I use this type of system in quite a few places. A lot of information in the databases, and constantly being moved in, out, and around, so brevity and speed are an issue.

Each database could have any number of keys. Maybe something using %numkeys to determine the number of local vars used, an incrementing local var creator extracting all the value strings, then comparing them all to the other database, adding or removing as needed, then storing them all back in. If it was only one key, easy enough, but even with the speed of local vars, still moving all the information in and out of the database, rather then just the subject ones would be nasty, I'd think.

That'd be the only thing I could come up with, and it seems like an inordinate amount of code with a serious speed penalty with the larger databases.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Sep 18, 2008 3:48 am   
 
For whatever reason the use of nesting a string list within a record variable doesn't work with the Dot Notation and #ADDITEM/#DELITEM. If it did work as you have it written, using a local variable will still likely be faster in your script, becuase it reduces the complexity of lookups and writes.
Code:
#addkey database1 key {val1|val2|val1|val3}
#addkey database2 {val1=1|val2=1}
#loopdb @database1 {
 $var=%val
 #forall {%val} {
  #if (%iskey( @database2, %i)) {#delitem $var {%i}}
 }
 #ADDKET database1 {%key} {$var}
}
#show @database1.key
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Thu Sep 18, 2008 4:21 am   
 
Ahh... Put the local variable creation there. I missed the obvious. Beautiful... Thank you. I'm one of those I need to actually see it before I can adapt it.

Tested it, and that route does work. Thank you all for the help.
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