|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Apr 07, 2010 5:52 am
Database Questions |
So, I've been reading all of the Scripting Reference stuff about Databases. There's a LOT there, needless to say, I've read it all but I don't feel as I've fully digested it all. From my understanding, the way to add new records to a database is to essentially create a Database Variable, give it a number of keys which match up with the fields in the database record, and then use the #NEW command to transfer.
However, all that I've read only seems to tell me how I can delete stuff from a Database Variable, but not the Variable itself. Nor do I see how I can replace items in the database record with what I know currently. I'm sure the information is right there, but I'm not processing it correctly. Any help would be appreciated. A better understanding of databases may work well for my newer scripts. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Apr 07, 2010 1:02 pm |
Have you checked the commands #DBPUT and #DBDELETE? That's how you change existing database records.
I'm not sure what you mean by "I can delete stuff from a Database Variable, but not the Variable itself". You delete a db variable the same way you delete any other variable, with #UNVAR. Or you can use a local variable as a db variable, and not worry about it. Am I misunderstanding your question here?
Are there any specific questions you have about dabases? It's a bit hard to give general help on it without knowing what you do or do not understand. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Apr 07, 2010 1:35 pm |
I saw #DBPUT, but I wasn't certain about it's use. I didn't see #DBDELETE in the reference section on Databases, perhaps I missed it. When I made the post I was half asleep, so I apologize for any confusing statements. The "I can delete stuff from a Database Variable but not the Variable itself" was a comment that you answered, what I meant to say that I could not delete stuff from a Database itself. I'll do some more research on the commands you gave, thanks for pointing me in the proper direction.
|
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Apr 07, 2010 1:40 pm |
Alright, so, one further question. Most of the references to accessing a database use examples of numbers to access records, but I'm not sure how a database numbers it's data. For instance, let's say I have a database with 3 records and 5 keys. So, something like
Code: |
Name Level Clan Class Rank
Record 1 [ ] [ ] [ ] [ ] [ ]
Record 2 [ ] [ ] [ ] [ ] [ ]
Record 3 [ ] [ ] [ ] [ ] [ ]
|
There's 15 records in there, how are they numbered? My imagining is that it's something like this:
Code: |
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
|
Is that correct?
Edit: Another question
I had seen %rec, but wasn't sure what it was. Now that I know it's a system assigned variable, I assume I can use something like
%rec = blah
in order to assign it? Does %rec refer to a single value in the database? (i.e. #13) or is there a way of replacing a whole row of a database, using a database variable created in the session? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Apr 07, 2010 4:33 pm |
In your diagram, there are only three records. A database record would be an entire row of your table. So, record 1 would be the Name, Level, Clan, Class, and Rank of record 1.
Records are often named for both the record number and the first two letters of the database, e.g. 1pc. This is why your databases should be named so the first two letters are unique.
When it says %rec is a system assigned variable, it means you can't assign it--it is assigned automatically by certain commands. #DBFIRST, #DBNEXT, #DBPREV, and #DBGET can set %rec.
You should look at all the database-related commands. Look at the "Database" page in the helpfiles; it lists most of them. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Apr 07, 2010 6:16 pm |
So, what you're saying is that 3 refers to all of Record Three. That %rec refers to Name, unless I use #DBNEXT, in which case it refers to Record3.Level. But if I can't alter %rec, how am I supposed to replace the value of Record.Level?
Edit: I'll continue reading. Eventually I'll get it, I'm sure. It's just a lot more complicated than anything I've run into in CMUD so far, and I'm not certain that the current setup of the helpfiles makes it any easier to understand. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed Apr 07, 2010 8:29 pm |
A record is a set of key=value pairs. To better explain it let's use your little table with some made up data.
Code: |
Name Level Clan Class Rank
Record 1 [Dumb ] [1000 ] [Super ] [Idiot ] [99 ]
Record 2 [John ] [10 ] [Jane ] [Missing] [1 ]
Record 3 [Doe ] [37 ] [Doe ] [Persons] [2 ] |
If that was your database and you did
#DBGET 2
#SHOWDB %rec
it would display
Name=John|Level=10|Clan=Jane|Class=Missing|Rank=1
Then doing
#DBNEXT
#SHOW %db(%rec,"Class") %db(%rec,"Level")
would display
Persons 37 |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Apr 07, 2010 9:08 pm |
Thanks Vijilante, that helps a lot. I'm also finding the Scripting Reference Database stuff more informational than the Feature Reference stuff. I think I'll have this down soon enough. I wanted to learn it since I wanted a trigger that stored the name of anyone I cast a particular spell on, along with the number of ticks it would last. Unfortunately, I couldn't use paired stringlists, because then I couldn't decrement the numbers as ticks passed by. Hopefully a database will be the solution to my problem. The only thing I'm worried about is that my use of the database is a bit more dynamic than the examples. I.E. the database examples show information that is generally stored indefinitely and with little changes, so I was worried that it would be difficult to work with a database that deleted records constantly and updated every tick. It looks like it will be complex, but doable.
Still trying to decide if there's anything in the nature of a database that would make me want to overhaul my Highlighter script with a database instead of the 4 or 5 stringlists I use now, all paired up and such. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 08, 2010 5:14 pm |
You're right, a Cmud database isn't all that fast and flexible for handling rapidly changing data. It is intended for relatively stable data. What you might want to use instead is a couple database variables. What would you want to store? Name, spell, and expiration tick? You could do that with two database variables; one might be pairs of Name/Spell, and the other Name/Expiration.
[Edit] The Features section of the help is not intended to give details of how to use the features--it is intended to give an overview of what is available. The details are in Scripting section, and pages on specific commands and functions. |
|
|
|
|
|