Author Topic: Coding a CMUD Database.  (Read 8534 times)

0 Members and 1 Guest are viewing this topic.

Brad

  • Fodder
  • *
  • Posts: 88
Coding a CMUD Database.
« on: January 23, 2014, 09:36:33 AM »
So I am trying to keep track of the many different types of spell components.  I decided that a database would be the best way to go about it, because it was already part of my client.  I wrote a script to put items into a database.  I am looking for a way to look through the database and see if an item is in there... It would be awesome if this returned a logical value.  This way i can tell the program whether to add an item to the database or not to.  I have used the #find and #query commands, but they return values I don't know how to deal with logically.  I have it running now but I have to go in and delete the doubles... That will get really annoying really fast.  Any ZMUD/CMUD guys around?

Thanks,
Brad

kanu

  • Fodder
  • *
  • Posts: 61
Re: Coding a CMUD Database.
« Reply #1 on: January 23, 2014, 02:25:35 PM »
Cough *** Export to relational database ** Cough, cough.

Anthony

  • Newbie
  • Posts: 38
Re: Coding a CMUD Database.
« Reply #2 on: January 23, 2014, 02:39:09 PM »
Using CMUD, you could just make a sqlite database, use #SQLDB and %sql commands. Then you could check if the returned object of %sql(db, "whatever query") had a RecordCount > 0 or not.

Brad

  • Fodder
  • *
  • Posts: 88
Re: Coding a CMUD Database.
« Reply #3 on: January 23, 2014, 02:44:45 PM »
I'll try the SQLite database.  It seems that there should be an inbuilt function to compare strings to strings in a field.  Might need to try and write one if I cant figure out the SQLite

I've tryed SQlite and can't figure it out.  I do have a database made in CMUD. Can i just type "#Sqldb Alchemy.db" and it will copy the alchemy database?
« Last Edit: January 23, 2014, 04:58:58 PM by Brad »

Anthony

  • Newbie
  • Posts: 38
Re: Coding a CMUD Database.
« Reply #4 on: January 23, 2014, 11:26:28 PM »
No, it opens the database. Then you can query it with %sql commands.

Brad

  • Fodder
  • *
  • Posts: 88
Re: Coding a CMUD Database.
« Reply #5 on: January 24, 2014, 12:42:07 AM »
OK I Give up. http://pastebin.com/LAnkrKFn

First person to fix it gets 20k coins.

Brad

corey

  • Zoner
  • **
  • Posts: 224
  • Favorite Zone: Brogs
Re: Coding a CMUD Database.
« Reply #6 on: January 24, 2014, 12:02:50 PM »
OK I Give up. http://pastebin.com/LAnkrKFn

First person to fix it gets 20k coins.

Brad

I don't know the syntax for whatever the hell it is you're using, but I can help with the logic. At what point(s) in the code are you looking for help and exactly what do you want spit out?

gulca

  • Zone Leader
  • ***
  • Posts: 308
Re: Coding a CMUD Database.
« Reply #7 on: January 24, 2014, 12:55:42 PM »
I don't use CMUD. Best to post it in the cmud forum for help. Here is a post regarding sql.

http://forums.zuggsoft.com/forums/viewtopic.php?t=28634

That's what I usually do when figuring out Tintin++ scripts.

Here is probably what is needed.

Query your database for the component and save it to a temp variable.
Compare temp variable with your new component.
Here is the if statement, if same, don't do anything. else update your database.



Baxter

  • Immortal
  • Newbie
  • *
  • Posts: 10
Re: Coding a CMUD Database.
« Reply #8 on: January 24, 2014, 01:52:00 PM »
Aren't you overwriting the variable doesexist in the loop?

So let's say you have 3 items in your database, and your component matches the second item, then doesexist = 1 when it checks the second item.  However, it then checks the third item and then doesexist = 0.

I think you'd need some kind of break statement after setting doesexist = 1, so that way it exits the loop and stops searching the database after it has found a match.

EDIT:
So I looked a little at CMUD stuff and I think I know how to fix this part.

Code: [Select]
#While %sql(!@row.Eof())   {
#if %sql(@row.Item("Name")=@Comp_Name) {#var doesexist=1}{#var doesexist=0}
}

Try this:

Code: [Select]
#var doesexist=0
#until (%sql(@row.Eof()) or @doesexist)   {
#if %sql(@row.Item("Name")=@Comp_Name) {#var doesexist=1}
}


Anyway, if that fixes it then good.  But please tell me what is the behavior of the code, so we can figure out where it is going wrong.
« Last Edit: January 24, 2014, 02:16:22 PM by Baxter »

Gyp

  • Immortal
  • Fodder
  • *
  • Posts: 53
Re: Coding a CMUD Database.
« Reply #9 on: January 26, 2014, 03:06:58 PM »
set dosomething to 1.
cycle through each row of the DB, comparing the .name section of that row to your comp name.
if it matches, set "dosomething" to 0 and do nothing.
if no match found, then (if dosomething > 0) run code to add to DB.

i'm going to fix this for you as soon as I have a cmud reg code :P

and you should use the SQL DB (which i've already figured out)

i'd already have this working for you if I had cmud.

40.00 is to rich for my blood this month!

Anthony

  • Newbie
  • Posts: 38
Re: Coding a CMUD Database.
« Reply #10 on: January 26, 2014, 06:38:00 PM »
The code you posted isn't the way you should do it. There is no reason to manually go through every row in the database.

The code is going to end up being something like this.

Code: [Select]
//Creating variables(taken from lines after "Brew" command)
#var Comp_Name %2
#var Comp_Qual %3
#var Comp_Type %4
 
// opening the database for comparison
db = %sqldb("Alchemy.sqlite")
 
row = %sql(db, "SELECT Name FROM Components Where Name = '@Comp_Name'")

#IF (@row.RecordCount == 0) {#call @db.Execute("INSERT INTO Components (Name, Quality, Type) VALUES (@Comp_Name, @Comp_Qual, @Comp_Type)")}


Gyp

  • Immortal
  • Fodder
  • *
  • Posts: 53
Re: Coding a CMUD Database.
« Reply #11 on: January 26, 2014, 07:36:44 PM »
I don't believe that row would be equal to 0 in that case.

Zugg has made it clear if you want to do something in SQL that doesn't return a result, you need to do it other ways, or it won't do anything.

I'm not sure what zugg's code would return in that case, maybe NULL which you could then check for, but he said you have to use other code to do SQL commands that don't return results.

your idea is solid though, but unfortunately (for us all) zugg's code uses SQL... uniquely.

and also, in zugg code, == doesn't exist either.  if a variable has @ in front, then it sets the variable, if there is no @ in front, then it checks equality.  both use =

Here is a reference list for Zugg code and their use of expressions.
http://www.zuggsoft.com/zmud/help6/Expressi.htm

Anthony

  • Newbie
  • Posts: 38
Re: Coding a CMUD Database.
« Reply #12 on: January 28, 2014, 11:20:18 AM »
Well, you're wrong...

Create the database.

Code: [Select]
>sqlite3 alchemy.sqlite
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table Components(name varchar(255), quality varchar(255), type varchar(255));
sqlite> pragma table_info(Components);
0|name|varchar(255)|0||0
1|quality|varchar(255)|0||0
2|type|varchar(255)|0||0
sqlite> insert into Components (name, quality, type) values ('a hairy sphincter', 'exceptional', 'summoning');
sqlite> select * from components;
a hairy sphincter|exceptional|summoning
sqlite> .quit

Create a simple alias to both test your outdated supposition on equalities and your assertion about sql select statements.

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="TestSql">
    <value>#sqldb alchemy.sqlite
row = %sql(alchemy, "SELECT Name FROM Components")
#if (@row.RecordCount == 0) { } {#echo @row.Item("Name")}
row = %sql(alchemy, "SELECT Name FROM Components Where Name = 'asdf'")
#if (@row.RecordCount == 0) { #echo "No Rows" }
#sqlclose alchemy
</value>
  </alias>
</cmud>

Examine the alias output:

Code: [Select]
a hairy sphincter
No Rows

Ezio

  • Fodder
  • *
  • Posts: 80
Re: Coding a CMUD Database.
« Reply #13 on: January 29, 2014, 09:32:18 PM »
Maybe I am a cynic here...but why are you doing this? There is low, mid, high, exceptional in each spell class. Maybe something else higher too I don't play mages, but I guess I don't understand the need to differentiate or record the 50 types of "low illusion" or whatever.

What I would do is go to each spell comp shop and type list. Write down the unlimited ones.

#alias kalamancomps {#showme {low healing/ low combat/low alteration/whatever}}

Then you know where all the unlimited components are. What else do you really need to know?

Brad

  • Fodder
  • *
  • Posts: 88
Re: Coding a CMUD Database.
« Reply #14 on: January 29, 2014, 11:12:10 PM »
If I am looking for a few high level Abjuration comps for a quest or to brew a buff...or whatever, I can put the word out to my friends.  Not everyone has access to the Brew/Scribe abilities, and are not able to determine the type of the different components they loot. I can give them a list of items to look for. Also, I want to.