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 Goto page 1, 2  Next
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Fri May 31, 2002 11:40 pm   

Accessing Database Query
 
I just finished importing everything into a database in zmud. Basically, I was wondering, how do you go about creating a trigger in game where someone says something like,

Jacob tells you, 'ID mask'

This will then query my database and tell him everything that is in my database related to 'mask'?



Sup
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jun 01, 2002 2:12 am   
 
I am not a DB expert. In fact I have specifically avoiding learning zMud DB scripting. Anyway the FIND command does on sort of DB query, and the queury function can provide you with a list of records that match in some way.

Beyond that I think you can figure the trigger needed to gather what to make the query from.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jun 01, 2002 4:14 am   
 
#TR {(%w) tells you, 'ID (%w)'} {#FORALL %find(%2) {tell %1 %viewrec(%i)}}

No guarantees at all. It may not work at all and if it does it might not be what you want. But it should give you enough of a start so you can find a way to do what you want. My personal trigger would probably be:
#TR {(%w) tells you, 'ID *'} {tell %1 no idea, look it up for yourself}

LightBulb
Vague questions get vague answers
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Sat Jun 01, 2002 2:42 pm   
 
Hehehe...nope it doesn't work...trying a few things but if anyone else has any ideas, by all means, let me know.

Sup
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Sat Jun 01, 2002 8:22 pm   
 
LightBulb's script doesn't work because %find returns the matched record in a different way than how %viewrec expects it. To have it work, change it to this:
#TRIGGER {(%w) tells you, 'ID (%w)'} {#FORALL %find(%2) {tell %1 %expanddb(%dbget(%i), " ")}}

Kjata
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Mon Jun 03, 2002 11:54 am   
 
Kjata:

I tried your trigger and it still doesn't work. Hrm...It doesn't send any replies. IT doesn't seem to do anything hehehehe...any suggestions?

Sup
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Mon Jun 03, 2002 2:07 pm   
 
A number of things you have to keep in mind are:

1. The db must be open.
2. It must be in the correct 'View'(preferably the 'All' View)
3. The record must exist for it to return anything at all.
4. Make sure the trigger pattern works.

Other than that, I see no reason the script shouldn't work.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jun 03, 2002 2:11 pm   
 
Is the database window open? If the answer to this is yes, then the next step would be to start performing some tests to see what %find is returning and then if %dbget and %expanddb are doing their job. However, this works perfectly for me.

Kjata
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Mon Jun 03, 2002 4:44 pm   
 
Database is open....

How do I perform test with %find? Do I just type %find?

Sup
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jun 03, 2002 8:38 pm   
 
Try to find out if %find is doing what it is supposed to do. For example, you might try entering in the command line:
#SH %find("sword")

This should return a string list containing the record number and short name of the database of all the records that match. If none match, it should give you a blank line.

Kjata
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Mon Jun 03, 2002 9:46 pm   
 
hrm...did the #SH %find("sword")

nothing showed up...seems like it didn't do anything.

Sup
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Mon Jun 03, 2002 10:16 pm   
 
What could be going wrong?

1. The db must be open.
It's open
2. It must be in the correct 'View'(preferably the 'All' View)
View All Set
3. The record must exist for it to return anything at all.
Record exists. There are tons of daggers for instance and did a #SH %find("dagger") and nada.

4. Make sure the trigger pattern works.
If it shows up then I can work on the triggers.




Sup
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Jun 04, 2002 12:02 am   
 
5. Make sure the record contains the desired information in the first column, unless you specified another column.

LightBulb
Vague questions get vague answers
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Tue Jun 04, 2002 12:19 am   
 
Now everytime I do the #sh %find ("shield")

it shows in the mud (shield)

Sup
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Jun 04, 2002 5:13 pm   
 
It doesn't show in the MUD, it just looks like it's comming from the MUD, that's what #SH does. Also, this happends because there is a space between %find and it's arguments.

Next, check to see that what LightBulb mentioned is true. %find looks for matches in the first column of the database. To check for matches in other columns, you need to use %query.

Kjata
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Tue Jun 04, 2002 6:04 pm   
 

>629fa|630fa|631fa|632fa|633fa|634fa|635fa|636fa|637fa|638fa|639fa|640fa|641fa619fa|620fa|621fa|...


This is what I get when I query.

Also whatever I query it's the same thing.

Sup
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Tue Jun 04, 2002 7:04 pm   
 
That doesnt elp much. %query by itself will always return the record numbers, as will %find. Here is what you need to do.

Open your db, and look at the first column. It should have the word "Records" above it. Now look down the list in the first column there will be the record numbers, in the second column there will be the record name, like this:


Records
-------------------------
|629fa| Mask of Illusion |
|630fa| Bee stinger |
|631fa| a halberd |
|633fa| dragon tatoo |
|634fa| Master's Whip |
-------------------------


Now THOSE are the names you will use %find for. %find doesnt even need the whole name. You could do a:

#FORALL %find(mas) {#SHOW %expanddb(%dbget(%i), " ")}}

and it would show both the "Mask of Illusion" and "Master's Whip" because they both have 'mas'.

If your first column have something wierd, like jsut numbers or something. You will need to select View->Customize, and make what ever field you want to be the first column. But that gets kinda complicated, so I suggest you read the help files on DB Views and filtering before modifing them.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Jun 04, 2002 7:17 pm   
 
nutsnbolts, try reading at least the help entries of all the commands that appear in the Database section of the Command Index as well as the functions that appear under the Database section of the Function Index. You can't script the database if you don't know what commands/functions are available to you, what they do and how to use them.

Kjata
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Tue Jun 04, 2002 8:00 pm   
 
That's what Im' trying to say, the column is all correct.

Records
| 3432fa | a pauldorn |
| 2324fa | a mask |
-----------------------

but when i cut n' paste your %find stuff and do for instance,
#FORALL %find(pauldron) {#SHOW %expanddb(%dbget(%i), " ")}}

Nothing happens.

The database is open, the view preference is ALL. Still it seems like %find doesn't do anything.






Sup
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Tue Jun 04, 2002 9:02 pm   
 
quote:

That's what Im' trying to say, the column is all correct.

Records
| 3432fa | a pauldorn |
| 2324fa | a mask |
-----------------------

but when i cut n' paste your %find stuff and do for instance,
#FORALL %find(pauldron) {#SHOW %expanddb(%dbget(%i), " ")}}

Nothing happens.

The database is open, the view preference is ALL. Still it seems like %find doesn't do anything.

Sup



Ok, the next step is to try and see whats failing.

Do this:
#SHOW %dbget(3432fa)

If that checks out ok(returns the record) then try this:

#SHOW %expanddb(%dbget(3432fa), " ")

If neither of those do anything, I dont know what to tell you. Maybe you managed to corrupt your DB already.I dont know. Sorry.
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Tue Jun 04, 2002 9:13 pm   
 
Yippee..progress..

Ok, I did this command: #SHOW %expanddb(%dbget(603fa), " ")

It gave me this:


Num=603fa Material=Le Name=a small goblin buckler Kind=Shield AntiClass Weight=3 Damage Room Comment=1H 2B 2A 1L +1Hit Gem Type Mana Level

What next?


Sup
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Jun 04, 2002 9:58 pm   
 
That helps a lot. That tells us that the first column of your database is actually "Material" and not the name. That's why your %find isn't working...zMUD is looking for "sword" or whatever in the "Material" field. To force it to look in the Name column, do this:

#SHOW %find("sword","","Name")

Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Tue Jun 04, 2002 11:04 pm   
 
Yes I just realized that. When I initially check what the first field was, according to the "LIST" view NAME was the first field.

I then went into the "FIELDS" view and realized that the layout was:

Material
Name
etc...

Although it didn't show it in the LIST VIEW, I didn't take into consideration that the FIELDS VIEW is what determines the layout.

The next question is then...

Anyway to pull out information and have it "say" in the mud the stats of a specific object found in the database? When I do a query. I know a tell would work but it crashes the zmud.

Like,
tell me ID mask
if there are 5 items in the database, it will try to tell them back to me but it crashes if there are a lot in the database.





Sup
Reply with quote
Castaway
GURU


Joined: 10 Oct 2000
Posts: 793
Location: Swindon, England

PostPosted: Wed Jun 05, 2002 8:36 am   
 
I guess it's accessing the database too fast.. try putting a delay in your loop.

Lady C.
Reply with quote
nutsnbolts
Apprentice


Joined: 01 May 2002
Posts: 188
Location: USA

PostPosted: Fri Jun 07, 2002 6:22 am   
 
How do I go about putting a delay in the loop?

Currently, this is the script Trigger I am using.

#TRIGGER {(%w) tells you, 'ID (%w)'} {#FORALL %find(%2) {tell %1 %expanddb(%dbget(%i), " ")}}

In addition, if there are more than 5 items found, how do I just stop it and have it display only 5 items and have it say something like, "Too many items found, please be more specific with item"

Sup
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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