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


Joined: 09 Mar 2003
Posts: 28

PostPosted: Sun Sep 07, 2003 1:48 am   

Starting a DB
 
Hello,
I am having huge trouble getting a DB started. I think it is that I can't get the naming convention down.

Could someone give me a simple example that I might be able to use
to get me going?

Thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Sep 07, 2003 4:40 am   
 
Well, there's a really simple example located in the help files...Smile. Since that's likely to confuse you just as much, how about you just tell us in specific detail what you're having trouble with?

Oh, and just in case you were wondering, you can't create a database via code; that has to be taken care of strictly via the DB window, or by an external database program like MS Access (ie, one that can handle the JET database format). I suppose you COULD write a plugin or a class that does this for you, but that's a whole lot of work for a whole lot of nothing.
Reply with quote
krohnu
Beginner


Joined: 09 Mar 2003
Posts: 28

PostPosted: Sun Sep 07, 2003 4:18 pm   
 
Like I said I think its mostly the naming convention. I guess what I am most lost on is how i am referancing the DB.

Lets say i have created a DB called test, it only has 4 fields, name, ac, worn, weight. I know how i can create a trigger to capture the info but I have no idea how to referance the DB to put it in.

Thanks
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Sep 07, 2003 7:11 pm   
 
This is from zMUD's built-in Help. I found it using Contents, Getting Started, Introduction to the Database, Programming the Database, Database Names.

Database Names

Databases have both a long text name, plus a filename for storing the database on disk. To refer to a database from the command line, you must use the first few unique characters of the filename. zMUD is designed for database filenames whose first two characters are unique. This two-character code is used throughout the scripting language to refer to the database. For example, you could have a database with a long name of "Equipment Database", and a filename of "equip.db". The two-character database code for this would be "eq". No other database should have a filename that starts with "eq". Make sure each database file starts with different characters.


Since your DB is "test", the first two characters are "te" and it would be referred to as "te".

#NEW is usually used when adding information to the database with triggers. This is covered in detail in the Help topics, Creating New Records and #NEW. However, #NEW does say, 'The optional second item of the View string list is the name of the Database to create the new record." No examples are given, and this is probably what's confusing you. To clarify the bit about addressing a database:
1. If you're only using one database, just use the name of the View. This will be ALL unless you have some other view you've defined and prefer to use.
#NEW All @dbinfo
2. If you have more than one database open, add the two-character name of the database after the View name as the second item of a stringlist, such as ALL|te.
#NEW All|te @dbinfo

If this isn't what's confusing you, please try to go into detail just like I did. It's much easier to answer questions when you don't have to guess what the other person is talking about. My first guess was that you couldn't figure out that "te" was the first two characters of "test".
Reply with quote
krohnu
Beginner


Joined: 09 Mar 2003
Posts: 28

PostPosted: Mon Sep 08, 2003 6:02 pm   
 
Well LightBulb again you help greatly, as I always seem to see with your respoces.

Though I think I am starting to understand the first part of it, but can we take it to the next level?

Lets say I want to add some new info to the DB and the trigger gets all the info and adds it to the DB. (just the syntax inside the trigger, the pattern is not really importain. This is more of the referanceing that I am lost on. Thanks!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Sep 08, 2003 10:41 pm   
 
This is the script I use:

#CLASS {ID}
#ALIAS StoreID {CapturingID=%query((&Name=@Affects));#DBRESET;Affects="";#FORALL @CapturingID {#DBGET {%i};#IF ((&TStats=@IDedItem.TStats)&(&Affects=@IDedItem.Affects)) { #ADDITEM Affects {%i}}};#IF (@Affects="") {#NEW All {Where=New Item};#DBFIRST;#WHILE (&Where!="New Item") {#DBNEXT};#ADDKEY %rec Where {Unknown};#ADDKEY %rec {%expanddb(@IDedItem)};#DBSAVE} { #ECHO Item appears to duplicate records @Affects .}}
#VAR CapturingID {} {}
#VAR Affects {} {}
#VAR IDedItem {} {}
#VAR IDsPending {}
#TRIGGER "IDCapture" {^Object '*' is type *, usable by *.$} {CapturingID=%line} "" {case}
#COND {} {#IF ((%ascii(%line)>64)&(%ascii(%line)<91)) { CapturingID=%concat(@CapturingID,"|",%line)} {#STATE IDCapture 2;#SET IDCapture 2 1}} {looplines|param=99}
#COND {} {CapturingID=%replace(@CapturingID,"Object '","KeyWords=");CapturingID=%replace(@CapturingID,"' is type ","|Type=");CapturingID=%replace(@CapturingID,", usable","|Classes");CapturingID=%replace(@CapturingID,"Extra flags ","|Flags=");CapturingID=%replace(@CapturingID,"Wear Location: ","|Wear=");CapturingID=%replace(@CapturingID,"Weapon type","|WType");CapturingID=%replace(@CapturingID," is ","=");CapturingID=%replace(@CapturingID," by ","=");CapturingID=%replace(@CapturingID,"Armor class","TStats=AC");CapturingID=%replace(@CapturingID," pierce, ","-");CapturingID=%replace(@CapturingID," bash, ","-");CapturingID=%replace(@CapturingID," slash, and ","-");CapturingID=%replace(@CapturingID," vs. magic.","");CapturingID=%replace(@CapturingID,"Damage","TStats=Dam");CapturingID=%replace(@CapturingID," to ","-");CapturingID=%replace(@CapturingID," (average ","A");CapturingID=%replace(@CapturingID,"("," ");CapturingID=%replace(@CapturingID,")","");CapturingID=%replace(@CapturingID,", ","|");CapturingID=%replace(@CapturingID,".","");CapturingID=%replaceitem(%word(%item(@CapturingID,4),1,","),4,@CapturingID);#DELITEM CapturingID {};Affects="";#FORALL @CapturingID { #IF ((%begins("%i","Affects"))|(%begins("%i","Causes"))) {CapturingID=%delitem("%i",@CapturingID);Affects=%additem(%trim(%remove(%word("%i",1),"%i")),@Affects)} { #IF (%begins("%i","Has")) {CapturingID=%delitem("%i",@CapturingID);Affects=%additem(%concat(%word("%i",3)," of L",%word("%i",7)," ",%copy("%i",%pos(%word("%i",8),"%i"),255)),@Affects)}}};#IF (@Affects) { CapturingID=%concat(@CapturingID,"|(Affects=",@Affects,")")};IDedItem="";#ADDKEY IDedItem @CapturingID;#IF (%db(@IDedItem,"Flags")="") {#ADDKEY IDedItem Flags ""};#ADDKEY IDedItem Wear {%replace(%db(@IDedItem,"Wear")," ",",")};Affects="";#WHILE (@Affects="") {#LOOPDB @ItemsOnHand { #IF (%word(%val,1)) {#ADDITEM Affects {%key}}};#FORALL @Affects { #IF (%pos(%lower(%word(%db(@IDedItem,"KeyWords"),1)),%lower("%i"))) {#DELITEM Affects {%i};Affects=%push("%i",@Affects)}};Affects=%pick("p:Item Name","o:1",@Affects)};#ADDKEY IDedItem Name @Affects;#LOOPDB @IDedItem { #IF (%pos("=",%val)) { #ADDKEY IDedItem {%key} {%concat(%char(34),%val,%char(34))}}};#DBLOAD ID;#VIEW All;#DBFIRST;#IF (%rec!="") { StoreID} {CapturingID=%concat("ID",%secs);#VAR @CapturingID @IDedItem {_nodef} {ID};#ADDITEM IDsPending @CapturingID}} {manual}
#BUTTON 3 "IDsPending:%numitems(@IDsPending)" {#IF (%numitems(@IDsPending)) {#DBOFFLINE;#DBLOAD ID;#VIEW All;#DBFIRST;#IF (%rec="") {#MENU {Windows|Database};#WHILE (%rec="") {#DBLOAD ID;#VIEW All;#DBFIRST}};IDedItem=@{%item(@IDsPending,1)};#UNVAR %pop(IDsPending) ID;Affects=%db(@IDedItem,"Name");StoreID}} {} {} {%numitems(@IDsPending)} {} {} {} {} {} {Pos} {1} {880} {32800} {} {Gauge||10|5|0|11} {} "" {Explore|Inset} {} {StoreIDs}
#CLASS 0

It provides detection and storage when the DB window is not open (DB window must be open to use the DB commands), since the detection is based on checking that the first record has some value you must create one record manually, even if it is blank. Also provided is a button to put held identifies into the DB, this button will force the window to open if you haven't opened it yet. Of course ID output on every mud is different, but the number of tweaks is very negligible and all preformed in a single trigger state (I have used this successfully on 2 heavily modded ROM based muds). The trigger decides that any line that does not start with a capital letter is not part of the ID, if this is not the case in your mud then more serious tweaking will be needed. Enjoy.
Reply with quote
krohnu
Beginner


Joined: 09 Mar 2003
Posts: 28

PostPosted: Tue Sep 09, 2003 6:04 am   
 
Okay, I think another small detail I must of been missing, you have to have the DB display open in order to use the db even triggers?

Maybe thats some of my confusion.

Thanks for all the insite so far! I will give tht set a try and see where that leaves me!

Krohnu
Reply with quote
mrmook
Beginner


Joined: 14 Jun 2003
Posts: 16
Location: USA

PostPosted: Tue Sep 09, 2003 6:41 pm   
 
Vijilante can you post an example of what you see with the lore command.
eg:
a Sword of the Ancients costs 3000 questpoints.
Object 'Sword Quest Ancient' is type weapon made of unknown material.
Wear flags take wield nosac, extra flags glow hum burnproof quest.
Weight is 3, value is 1000qp, level is 202.
Weapon type is sword.
Damage is 202d5 (average 606).
Damage type is slice.
Weapons flags: flaming nodisarm
Affects damroll by 20.
Affects hitroll by 20.

I ask this because i was unable to get your script to record from my lore command and am not the great pimp you seem to be with scripting... so i was lookin for a lil help..

the previous is exact output from the mud via "lore <item>" command or in this cast "quest id sword"

any help would be AWESOME.. lookin for a full database to store everything.. and yes im lookin thru the older topics heh heh

thanks for anything you can do
Mr Mook
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Sep 10, 2003 1:04 am   
 
Mr. Mook, the script is designed to replace various things with a 'key'= so that they can be put into a record variable directly with a single #ADDKEY command. Start by reading the help on that so you understand that portion.

Everything is done by way of those replacements. For example my mud has extra flags on a seperate line, yours does not. In both case there is a replacement though because there is no "is" or "by" between what we want for a key name and the value potion.
My replacement:
CapturingID=%replace(@CapturingID,"Extra flags ","|Flags=")
Yours would be:
CapturingID=%replace(@CapturingID,", extra flags ","|Flags=")

In mine no damage type is given by the ID, and no distinct weapon flags are provided. These would be handled simply by adding lines like:
CapturingID=%replace(@CapturingID,"Damage type","DType")
CapturingID=%replace(@CapturingID,"Weapon flags: ","WFlags=")

Just make sure when you create the DB you have fields that match the names you use, I like 1 word field names, but you might not. In general you want to avoid lines like this one (that is in there):
CapturingID=%replaceitem(%word(%item(@CapturingID,4),1,","),4,@CapturingID)
It is better to do replacements and formatting that are specific to a key after it has been put into the record variable such as this line:
#ADDKEY IDedItem Wear {%replace(%db(@IDedItem,"Wear")," ",",")}
which formats the Wear field to work as an Option List type when put into the DB.

Best bet is to tweak around on it and if it breaks just grab a new copy from the forums.
Reply with quote
mrmook
Beginner


Joined: 14 Jun 2003
Posts: 16
Location: USA

PostPosted: Wed Sep 10, 2003 10:09 pm   
 
thanks for the help and im playin with it so ill see what happens :P
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