|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Fri Jun 28, 2002 10:01 am
Databases, ugh. |
I've poured through the helpfiles that come with zMUD, and dozens of posts here, but I still can't get this simple script to run! Any idea what I'm doing wrong?
The idea of this script is to keep track of how often I mine up certain materials, and how much I get doing it. Here's what I've got:
Trigger: You mine (%d) pounds of (*).
Action:
#ADDKEY mat Total %1
#ADDKEY mat Name %2
testalias
Alias: testalias
Action:
#DBLOAD or
#QUERY &Name=@mat.Name All 1
#IF (%null( %rec)) {
#NEW All @mat
}{
#VAR newmat ""
#ADDKEY newmat Hits %rec.Hits+1
#ADDKEY newmat Total %rec.Total+@mat.Total
#DBPUT %rec @newmat
}
#DBSAVE
All this does is send "{#NEW All Total1NameironHits1}{#VAR newmat ;#ADDKEY newmat Hits +1;#ADDKEY newmat Total +1;#DBPUT }" directly to the MUD!
For reasons unknown to me, if I change the if statement to "#IF !(%null( %rec)) {" and switch around the blocks below it, it interprets the if correctly and sends nothing to the mud, but still doesn't add anything to the database.
Ugh, maybe this isn't worth the effort I've put into it. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Fri Jun 28, 2002 11:26 am |
You need a space between the if block and the else block. It's:
#IF (%null(%rec)) {
...
} {
...
}
Kjata |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Fri Jun 28, 2002 11:50 am |
That works, now it doesn't matter what order I put the blocks in. But it still doesn't add anything to the database. Anymore suggestions?
|
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Sat Jun 29, 2002 11:43 pm |
No more suggestions for me?
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun Jun 30, 2002 5:11 am |
I'm sorry I can't be more helpful, but I can't see anything wrong with the script. The only thing I can do is offer a little debugging advice.
Clear your variables.
#VAR mat {}
#VAR newmat {}
Check what's in your database, you'll need to know in a little bit.
Go mine something. Check the values of your variables.
#VAR mat
#VAR newmat
If @mat doesn't match what you just mined, your trigger needs work.
If @newmat doesn't match, there are two possibilities. One is that it's a new material that's not in the database. The other is that your alias needs work.
Finally (or perhaps you should do this first), check that you've actually created the database (or) with the appropriate fields (Total, Name, Hits). You might also need to use the #DBONLINE command following the #DBLOAD command.
That's all I can think of, good luck.
LightBulb
Senior Member |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Sun Jun 30, 2002 10:33 am |
The database has all the appropriate fields, but you mentioned that one problem might be that the materials do not exist. They don't, I didn't add them manually, I thought that this:
#IF (%null( %rec)) {
#NEW All @mat
}
was supposed to add new materials to the database. ..was I wrong? Do I need to add all the materials manually? (There's nearly two hundred, I hope this isn't the case.) |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sun Jun 30, 2002 2:06 pm |
Sometimes you need to create the first record yourself before the datbase will respond to scripts correctly. Try that to see if it helps.
Kjata |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Sun Jun 30, 2002 11:09 pm |
i've created the first record, it makes no difference.
|
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sun Jun 30, 2002 11:13 pm |
Don't take this qeustion wrong if you find it stupid, but is the database window open?
Kjata |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Mon Jul 01, 2002 9:08 pm |
The window itself has to be open? It's not enough that I'm using #DBLOAD to put in accessible memory?
If this is the case, it seems like quite a design flaw. I'd like this database to update every minute or so while I enjoy the mud, keeping that window itself open would surely be quite an inconvenience. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Jul 01, 2002 11:19 pm |
Yes, the window needs ot be open. This is done to conserve memory. If you don't have the datbase window open, then none of the associated functionality is present.
However, you do not need to have the window in front of you, you can dock it and make it into a tab that sits beside the tab of your main window. Just make sure that Lock Layout is not selected in the Layout menu and that Dockable is selected in the menu for the database window. Drag the database window until you see the outline lock into place in the center of the main window and then it will form a tab and stay there hidden. Enable Lock Layout and save the layout to have it always open like this.
Kjata |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Mon Jul 01, 2002 11:29 pm |
Well, I'll resign that argument now because of the other great things zMUD has done for me. I would request, though, that another way to do this be looked into.
Yes, that works. The database is updating nicely, but I'm getting an infinite loop error when I'm running this short script now.
Trigger: You mine (%d) (%w) of (*) from your surroundings.
Action:
#VAR mat {}
#ADDKEY mat Total %1
#ADDKEY mat Name %3
#ADDKEY mat Hits 1
oredatabase
Alias: oredatabase
Action:
#DBLOAD or
#DBONLINE
#IF (%null( %find( %db( @mat, Name)))) {
#NEW All @mat
} {
#VAR newmat {}
#ADDKEY newmat Name @mat.Name
#ADDKEY newmat Hits {%abs( %rec.Hits + 1)}
#ADDKEY newmat Total {%abs( %rec.Total+@mat.Total)}
#DBPUT %rec @newmat
}
#DBSAVE
I'm having trouble pinpointing the origin of this loop, I don't see where I call anything inside of it. Any more advice? :) |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Jul 01, 2002 11:41 pm |
I don't know if this is the cause of the loop, but you seem to have a problem in your use of %rec. %rec is the current database record, but if an item you are trying to add already exists, %find won't make %rec into that item, but #FIND will. So, if you are going to use %find then you need to change things around a bit taking into account what %find returns (the record number that matches the string.) Also, you use #DBPUT with %rec as an argument, but #DBPUT doesn;t accept a record as an argument, but a record number. So perhaps your script should be:
#VAR mat {}
#ADDKEY mat Total %1
#ADDKEY mat Name %3
#ADDKEY mat Hits 1
oredatabase
Alias: oredatabase
Action:
#DBLOAD or
#DBONLINE
#IF (%null( %find( %db( @mat, Name)))) {
#NEW All @mat
} {
#VAR newmat {}
#ADDKEY newmat Name @mat.Name
#ADDKEY newmat Hits {%abs( %db(%dbget(%find( %db( @mat, Name))),Hits) + 1)}
#ADDKEY newmat Total {%abs( %db(%dbget(%find( %db( @mat, Name))),Total)+@mat.Total)}
#DBPUT %find( %db( @mat, Name)) @newmat
}
#DBSAVE
Kjata |
|
|
|
Sitral Beginner
Joined: 03 Mar 2002 Posts: 15 Location: USA
|
Posted: Tue Jul 02, 2002 12:01 am |
Yes, I see what you mean about %find, thanks for the advice.
Now, though, there are apparently two infinite loops. Everything works perfectly (everything I can see, anyhow), except for that nuisance of a message...*Sigh*
Edit: Blah, docking the database messes with the alt keys. Hitting (alt) then (F) results in the database file menu opening, rather then the file menu for the main window. |
|
|
|
|
|