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


Joined: 18 Aug 2009
Posts: 14

PostPosted: Sun Aug 26, 2012 6:36 pm   

updating and extracting database in cmud when command(s) are given.
 
I am new to database, and have been thinking for years, to make one, and upon reading help files being dumbfounded.

yes. I know how to create any trigger possible with variables, multiple trigger lines, and usually end up storing data in variables instead of a database.

now here is what Im looking at:
[46 class1 ] name0 (Lich)
[46 class1 ] name1 title (Lich)
[45 class2 ] name2 this is a bigger title clan1 (Phantom)
[42 class3 ] name3 amazing long title that I wouldnt need clan2 (Barbarian)

So I figure, with around 300 people on and off the mud I see their race and have to make a trigger when they enter my room/when I type look and output some info on what their class is, as I am very fragile to some class. pvp by the way.


so what I found trying to code this, was. variables dont stand a chance to hold the data I need. or I can make a trigger for each name and #echo it, which I would have to update.


I am sorry for asking. but how in gods name do I find info on how to create the database, and upon typing who update the database on their race and class name to display with a #echo?

I dont need the triggers, I need to know the commands to update and extract info to and from the database.

the actual triggers I use is to trigger when I look or enter a room on top of someone, to display their class and level.
Reply with quote
shalimar
GURU


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

PostPosted: Sun Aug 26, 2012 6:57 pm   
 
depends on if you mean an actual sql database, or a variable database, i prefer the variable method myself

Read the various #HELP files: #ADDKEY, #DELKEY #SHOWDB
_________________
Discord: Shalimarwildcat
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Sun Aug 26, 2012 7:10 pm   
 
I mean the database inside cmud.

I found &class lists the variable but I want to learn using the cmud database to later develope a item database. so I start off easy.


I just need to know:

Add a field value (I have 4 fields, level class name race)

update fields level
check if record for name exists
display a field(s) in #echo

#addkey will not work as #showdb lists several lines. I can have up to 20 enemies in a single room.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Aug 26, 2012 7:29 pm   
 
The in-cmud database module is a REALLY old feature, and is a proprietary flat-file format (no other database applications can read it). It's relatively buggy, and most users are either not using it or have switched to the SQL features. If you really want to learn how to use it, open up the Documents window (Help menu, the Contents option will take you there) and start looking under the Feature Reference section.
_________________
EDIT: I didn't like my old signature
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Sun Aug 26, 2012 8:02 pm   
 
what did I do wrong here?
field1 is name
field2 is race
field3 is class
field4 is level
this is the trigger action:
and I get a error: does not compile

%3 is in trigger the name

#if {%iskey(name) = %3}
{#echo already in}
{#addkey {name=%3|level=%1|class=%2|race=%4}
}
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Aug 26, 2012 8:12 pm   
 
Proper syntax matters in cmud. () has to go around expression arguments (see the #if helpfile).
_________________
EDIT: I didn't like my old signature
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Sun Aug 26, 2012 8:29 pm   
 
thank you for that excess of retorical exponation.

alright. so back to database inside cmud. I will have to figure out how to use it, unless someone has an example of how its used. this would be greatly appreciated.
Reply with quote
shalimar
GURU


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

PostPosted: Sun Aug 26, 2012 9:20 pm   
 
I can give you plenty of examples for a dbVariable, but the module you are using i never bothered with... how married are you to using that DB?
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Sun Aug 26, 2012 9:26 pm   
 
#ADDKEY people.merlin {class=wizard}
#ADDKEY people.merlin {race=human}
#SHOWDB @people.merlin

#SAYADD @people.merlin.class @people.merlin.race
_________________
Discord: Shalimarwildcat
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sun Aug 26, 2012 11:20 pm   
 
gukk wrote:
what did I do wrong here?
field1 is name
field2 is race
field3 is class
field4 is level
this is the trigger action:
and I get a error: does not compile

%3 is in trigger the name

#if {%iskey(name) = %3}
{#echo already in}
{#addkey {name=%3|level=%1|class=%2|race=%4}
}

Actually, you have a lot of errors here.

As Matt said, you need parentheses around the expression in #IF.
%iskey takes two arguments--the database record number or db variable name, and the record key.
#ADDKEY takes three arguments--the name of the db variable, the name of the key, and the value (which can itself be a stringlist or set of key/value pairs) to associate with the key.
If you are trying to use the internal database, #ADDKEY will not work. That is only used for database variables.
And finally, the parameters %1, %2, %3, and %4 do not match what you described in the beginning. Is %1 the name or the level? Is field 2 the race or the class?

I strongly suggest that you give up trying to use the internal database system. We can help you use either an SQL database or a database variable--and a database variable _can_ handle what you are trying to do. Shalimar has given some good examples of what you can do with database variables.
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Sun Aug 26, 2012 11:44 pm   
 
Quote:
I strongly suggest that you give up trying to use the internal database system. We can help you use either an SQL database or a database variable--and a database variable _can_ handle what you are trying to do. Shalimar has given some good examples of what you can do with database variables.




that sounds amazing. So I install a sql or sql lite and run a external input system to cmud? once I know how to I can add a autoadd of equipment too... perfect! what do I need?

Also, yes, I figured out how to use the #addkey... just a bit limited with variables, which %db gets around... I guess the help files for the cmud database system confused me too much.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Aug 27, 2012 1:00 am   
 
If you know SQL, connecting a database to Cmud is actually quite easy. The only commands and functions that you need are: #SQLDB[to create a connection and open it] or %sqldb() [to create a connection and return a COM object] , #SQLCLOSE [to close a connection], and %sql() [to execute an arbitrary SQL command string]. All of these are documented.

One limitation is that if you want to use something other than SQLite, you need CmudPro. But SQLite will probably be sufficient for you?

Here are a couple examples:
Code:

#SQLDB sessions.db
row = %sql(sessions, "SELECT * FROM chartable")
#WHILE (!@row.Eof()) {#SHOW @row.Item("Title");#CALL @row.Next}
#SQLCLOSE sessions


Code:

db = %sqldb("MyDB", "dbname", "mysql", "server.com", 3305)
db.LoginPrompt = 1
#CALL @db.Open
#CALL @db.Execute(%concat("INSERT INTO chartable (Name, Race, Class, Level) VALUES ('", %1, "', '", %2, "', '", %3, "', '", %4, "')"))
#CALL @db.Close
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Aug 27, 2012 2:05 am   
 
Quote:

So I install a sql or sql lite and run a external input system to cmud?


To actually work with the SQLite database system in CMud, you don't need to install anything. However, the totality of the feature is basically a half-dozen commands and functions. Not much of a UI to learn on, plus it's new with some unhandled errors and things that need to be adjusted.

If you want the UI experience, a database client (ie, MS Access, SQLite Expert, etc) is recommended as it does for databases what CMud does for mudding. Such a tool is also handy if you want to do SQL work without opening up CMud. Combined with tutorial websites like w3schools.com, you should be able to gain familiarity quickly.
_________________
EDIT: I didn't like my old signature
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Mon Aug 27, 2012 1:08 pm   
 
cool. I have cmud pro already. however I decided to use mysql.

Going to attempt to make triggers like specified by you earlier. also, a identify script :)
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Mon Aug 27, 2012 1:23 pm   
 
so I use this on mysql ...

db = %sqldb("MyDB", "dbname", "mysql", "localhost", 3306)
db.LoginPrompt = 1
#CALL @db.Open
#CALL @db.Execute(%concat("INSERT INTO chartable (Name, Race, Class, Level) VALUES ('", %1, "', '", %2, "', '", %3, "', '", %4, "')"))
#CALL @db.Close

Dont I have to type a password to enter into it? also, how do I get the database to load a certain character's specifications into cmud pro?
like, and echo or show.

thanks for all your help already! awesome!
edit:
also.... I would want no duplicate entries for a name..
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Aug 27, 2012 8:53 pm   
 
It should prompt you for a username and password when you open the database, since you set LoginPrompt to 1. You could also hardcode the username and password if you want, with this code: db = %sqldb("MyDB", "dbname", "mysql", "localhost", 3306, "username", "password"). That's less hassle for you, since you won't need to type the password every time you want to open the database, but it's less secure, anyone who gets their hands on your settings can just look at your password in plaintext.

Rahab's first example shows how you would use %sql to select data from the database. Preventing duplicate entries would fall into the realm of table design - make the name a primary key and you won't be able to duplicate it.
Reply with quote
gukk
Beginner


Joined: 18 Aug 2009
Posts: 14

PostPosted: Tue Aug 28, 2012 4:44 am   
 
how about "ansi" trigger for a equipment database? so the duplicates with diffrent colors react one way?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Aug 28, 2012 2:12 pm   
 
I'm not sure what you mean. Do you actually want to store the color in the database? If you do, how do you want it to handle a red "myname" when there is already a green "myname" in the database? Do you want the red version to replace the green one, or become a new entry? Your question is a bit confusing.
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