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
Affinity
Newbie


Joined: 07 Jan 2007
Posts: 1

PostPosted: Thu Jan 11, 2007 8:28 am   

Using the #DB commands
 
I have been trying for the longest time to incorporate the DB into zmud, and now cmud. Here is a sample alias that I am using (It looks up a description in the DB and prints all matching names):
Code:

#DBRESET
#DBLOAD descriptions.mdb
$recordsfound=%find( %1, "de", 3)
#if (%numitems( $recordsfound)>=1) {
$namelist=""
#loop 1,%numitems( $recordsfound) {
#dbget %item( $recordsfound, %{i})
$name=%rec.name
$namelist=%concat($namelist," ",$name)
}
#echo Names found: $namelist
}
#dbreset
#dbclose de


I have tried several variations of this and keep having a few issues.

First, I have to force the DB window to be opened, or else the %find() returns no results. I tried using #MENU {Tools|Database} first, but in CMud this now forces the database window to popup in front. This is very problematic for my DB-based triggers.

Second, if I have multiple tables open, I have been unable to find a consistent set of #DB commands to switch from one to the other. I'll find that multiple copies of the same database are opened, or that the %find searches the wrong database, or #DBGET cannot load the record, or worst case, I get an appllication error.

Does anyone have examples that they can post where the DB works for them consistently? I'd really like to see an alias that:
1) Opens a database if it is not loaded
2) Does a %find or similar to retrieve a list of records
3) Does a #DBGET to load the reccord
4) Does a #DBSAVE to save a changed record
5) Closes the database or does whatever commands are needed so 1-4 can be run a second time, and behaves in the same way.

Will the coming new DB module be easier to work with? Please help, many of my key aliases and triggers depend on storing data in the database.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Jan 11, 2007 10:55 pm   
 
This isn't all of what you asked for but here is my AddToDB alias
Code:
#DBLOAD Equipment
#IF (%query( "( &Name==@CurItem.Name ) && ( &Level==@CurItem.Level)&&( &Value==@CurItem.Value)")) {
    #NOOP
    #mess Match Found
} {
    #NEW @CurItem.Kind {@CurItem}
}
#DBSAVE Equipment
#UNVAR CurItem


@CurItem is a database variable that has been populated to the corresponding fields of equipment. The code first checks to see if there is a record that matches Name, Level and value using %query and inserts it if there is not.

That should Answer 1,2, and 4. As for 5, I guess it answers it as well since I use this as a repeatable unit of work.
_________________
Asati di tempari!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Jan 11, 2007 11:39 pm   
 
Slightly offtopic, how well do you find #mess works? I've always favoured using #say since it stays in the log forever, you can run triggers off it and such. It doesn't draw the eye very well either, I don't think.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Jan 12, 2007 1:47 am   
 
I usually use #Mess for debug... actually forgot to take that out. Also I don't do too much logging. I use #SAY sometimes but in the past I've had it throw off some other triggers (depending on the the output is.)
_________________
Asati di tempari!
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Feb 07, 2008 5:16 am   
 
Sorry to bump this up quite a bit, but my question is highly along the same lines.

Whenever I start CMUD back up, I /must/ click on Database in order to get the module up and running. No amount of "#DBLOAD mobfinder" will bring the module up, and therefore, my script will not work. Am I missing something? Also, I'm surprised that the open DB module does not save with the layout, even after #SAVE and whatnot. How can I make it so I don't have to click Database all the time?

Charneus
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Thu Feb 07, 2008 5:49 am   
 
#MENU {windows|Database}

Opens the database without having to click on it.

#MENU {Database|file|exit without saving}

Closes the database without saving any of the changes you made. I use it for reading info from the database.

#MENU {Database|file|exit}
Closes the database, not really sure if this saves your stuff first or not.

#MENU {Database|file|save}
Should save your database if the file exit doesn't.

There used to be a delay before you could use the information in the database back in Zmud I have not used the database much in Cmud so I don't know if it is still required. I would give it half a second to load before I tried to use it.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
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