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
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Tue Feb 12, 2002 12:04 am   

DB Help
 
Ttrying to make a script that will find a record from my database and return a spicified field, so that i can #SEND...just the field. Thanks in advance :)
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Feb 12, 2002 12:37 pm   
 
Take a look at these functions:
%db
%dbget
%find
%query

Kjata
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Tue Feb 12, 2002 2:50 pm   
 
I have, and i've experimented with them, and im not getting any results(well, not the results i want anyways)
What I want to do is something like:
#ALIAS {goto} {#SEND %db(mobs,SpeedW,%1)}
and have it send the SpeedW field to the mud...

Still playing around with it...
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Feb 12, 2002 6:13 pm   
 
Hmm, I'm not sure what you are trying to get from the database. %db only accepts two arguments. Are you looking for the value of the SpeedW field associated with a particular mob in the Mobs field, or are you looking for some value in the SpeedW field which is located in the mobs view? More info please.

Kjata
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Tue Feb 12, 2002 8:15 pm   
 
Ok, I have a DB named Mobs, and the fields are Name,Area,Room,SpeedW. What im trying to do is make an alias that sends the SpeedW field of a given mob directly to the mud.I have an another alias settup to #find the mob, so the %1 should probably be the record number.

Hmmm, I could have sworn when i was looking thru the help files it syntax was:
%db(rec,key[num])
but i just checked again and your right, so i dont know where i got that, probably from another command.
EDIT: Ah, yes. The mob find alias is a real simple:
#alias fmob {#FIND %1}
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Feb 12, 2002 11:33 pm   
 
The problem with #FIND is that it just changes the current display of the database to show only those that match your criteria. However, you can use the functions, to make it all more automatic. Here is an example:
#ALIAS goto {#IF (!%find("%1")) {#SAY That mob name does not exist in the database.} {#SEND %db(%dbget(%find("%1")), "SpeedW")}}

This is the simple one which assumes that whatever you supply to the alias as an argument will not match more than one mob name. If it may match more than one mob name, then this one will do the trick:
#ALIAS goto {#IF (!%find("%1")) {#SAY That mob name does not exist in the database.} {#IF (%numitems(%find("%1")) = 1) {#SEND %db(%dbget(%find("%1")), "SpeedW")} {#VAR moblist "p:Select a mob to go to|o:1";#FORALL %find("%1") {#VAR moblist %concat(@moblist, "|", %db(%dbget(%i), "Name"), ":#SEND ", %db(%dbget(%i), "SpeedW"))};#PICK @moblist}}}


Kjata
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Wed Feb 13, 2002 12:11 am   
 
quote:

#ALIAS goto {#IF (!%find("%1")) {#SAY That mob name does not exist in the database.} {#IF (%numitems(%find("%1")) = 1) {#SEND %db(%dbget(%find("%1")), "SpeedW")} {#VAR moblist "p:Select a mob to go to|o:1";#FORALL %find("%1") {#VAR moblist %concat(@moblist, "|", %db(%dbget(%i), "Name"), ":#SEND ", %db(%dbget(%i), "SpeedW"))};#PICK @moblist}}}


Kjata


*awe-struck*
That works !EXACTLY! the way I wanted it to.I can express enough how grateful I am.You rock Kjata!
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Wed Feb 20, 2002 1:09 am   
 
Spoke to soon.
The problem with this script is that when I have a mob that doesnt have any other matches(i.e. does not bring up the #PICK window) it doesnt expand aliases that I put in some of the 'SpeedW' fields.Now if I just leave part of the name off, and force it to use the #PICK window, then it will expand that alias normally.Small matter, but maybe a bug?
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Wed Feb 20, 2002 1:41 pm   
 
The problem is that the script uses #SEND because that is what you posted the example. #SEND works a little bit differently than if you just put the commands in the command line, so I guess you are just going to have to change #SEND for #EXEC. However, you are going to have to put up with the commands being displayed.

Kjata
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Wed Feb 20, 2002 9:15 pm   
 
No good. Does the same thing.Though I rather see the commands executed on the screen :).I DID change the script a bit...just to change the output for the pick window, but I JUST now did that...after I tested with #EXEC.

Anyways...heres the changes:
#IF (!%find( "%1")) {#SAY That mob name does not exist in the database.} {#IF (%numitems( %find( "%1")) = 1) {#EXEC %db( %dbget( %find( "%1")), "SpeedW")} {
#VAR moblist "p:Select a mob to go to|o:1"
#FORALL %find( "%1") {#VAR moblist %concat( @moblist, "|", %db( %dbget( %i), "Name"), "-", %db( %dbget( %i), "Room"), "-", %db( %dbget( %i), "Area"), ":#EXEC ", %db( %dbget( %i), "SpeedW"))}
#PICK @moblist
}}
as you can see, all i did was make it so i can see some of the other fields in the pick window for further clarification.

Again, the problem is this...
I have an alias that opens a text file, grabs some text, sends it to the mud, and closes the file. it look like this:
#CLASS {SWStuff}
#ALIAS swfile {swfname=%1}
#ALIAS swtell {getsw %1;#IF (@swexist) {tell %2 @swtitle= @swinfo}}
#ALIAS swlist {swname="";swnum=1;#FILE 1 @swfname;#WHILE (@swname != "end") {swname=%read( 1, @swnum);#IF (@swname != "end") {#ADD swnum 1;swtitle=%read( 1, @swnum);#ADD swnum 2;#ECHO @{swtitle}: @swname}};#CLOSE 1}
#ALIAS runto {enter;getsw %1;#if (@swexist) {#ECHO Running to @swtitle;#LOOP 1,%numwords( @swinfo, ";") {%word( @swinfo, %i, ";")}}}
#ALIAS getsw {swname="";swnum=-2;#FILE 1 @swfname;#WHILE (@swname != %1 & @swname != "end") {#ADD swnum 3;swname=%read(1,@swnum)};#IF (@swname != "end") {#ADD swnum 1;swtitle=%read(1,@swnum);#ADD swnum 1;swinfo=%read(1,@swnum);swexist=1} {#ECHO Speedwalk %1 doesn't exist in @swfname;swexist=0};#CLOSE 1}
#VAR swname {underdark}
#VAR swinfo {sprint d4sds4e2ne8d;open west;w}
#VAR swfname {myswfile.sw}
#VAR swnum {606}
#VAR swtitle {Underdark}
#VAR swexist {1}
#CLASS 0

ya, its a little messy, i just left all the current values in there, but you get the idea.When I type runto underdark, it loops and finds that part of the text file and, echo's me where im running to, and sends the sprint command. Now when I #send or #exec the 'runto underdark' alias thru the pick window, it work just fine.But if i type 'goto -precise mobname-' and it doesnt have to call the pick window, it sends the alias to the mud without executing it...

Does that help some?
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Feb 21, 2002 12:39 am   
 
That is very strange. I see no reason why it should expand the alias with the pick window, but not without it since it is executing the exact same command, but with different arguments.

Since I don't have your file, database, alias, etc., I'm going to need your help in seeing where the problem is. Try replacing the #EXECs by #SHs and look at what is displayed. Get an example of what is displayed when you search for a mob that doesn't bring up the picklist and when you search for one that does bring up the pick list.

Kjata
Reply with quote
dacheeba
Adept


Joined: 29 Oct 2001
Posts: 250

PostPosted: Thu Feb 21, 2002 2:31 am   
 
Ok this makes it odder(is that a word?).I did as you said, and replaced the #EXEC ' with #SHOW and did the following:
Command Line: goto jarre//thats the mobs full name.

and the output is what you would expect it to be:
runto underdark
sprint 5w
op n
sprint 2ne//(this was just shown, NOT sent.)

but when I failed to elaborate the name, in order to get the example for the pick window, like so:
Command Line: goto j
the pick window came up and offered me the choices:
Juicy Steak
Jarre
[OK] [Cancel]

I select jarre and hit ok, and it sends the commands to the mud!The alias got expanded and it took me straight to Jarre, inspit of the fact that i changed:
#FORALL %find( "%1") {#VAR moblist %concat( @moblist, "|", %db( %dbget( %i), "Name"), "-", %db( %dbget( %i), "Room"), "-", %db( %dbget( %i), "Area"), ":#EXEC ", %db( %dbget( %i), "SpeedW"))}
#PICK @moblist
}}

to:
#FORALL %find( "%1") {#VAR moblist %concat( @moblist, "|", %db( %dbget( %i), "Name"), "-", %db( %dbget( %i), "Room"), "-", %db( %dbget( %i), "Area"), ":#SHOW ", %db( %dbget( %i), "SpeedW"))}
#PICK @moblist
}}
!!!
So the only thing i can think of is that its forcing an expansion due to how the pick window is parsed!(probably way off too :P)

Tested another idea i took the ":#SHOW " out all together and tryed to call the pick window.I called the approriate records(tho the format was WAY sloppy) clicked ok, and it STILL expanded that alias and sent it to the mud.

Ask if you need me to try something else...

EDIT: Hrmm, maybe I sould move the topic to Beta forum, as thats what im using...6.25a
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Feb 21, 2002 5:04 am   
 
Still very strange, hehe. I don't have any idea why it does it like this. You can try posting in the Beta Forum and see if Zugg knows something.

Kjata
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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