Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
haderach
Newbie


Joined: 10 May 2007
Posts: 4

PostPosted: Thu May 10, 2007 10:06 pm   

#query with variables
 
I've been testing out CMUD using the scripts that I have been using in ZMud. One of the triggers that I have though, refuses to work. I was wondering if anyone else noticed the same behavior or if I am missing something.

The following code triggers on a regular expression

Code:
#var desc {%1}
#dbload herbs
#query (&description = @desc) herbs 1


For whatever reason, no records get found. However, if I run the same code (#query) from the command line or if you put a regular string there instead of the variable, it retrieves the correct value. Furthermore, it appears that simple uses of variables in the trigger script. Here's an example

Code:
#say {This is the description @desc that is stored}


This will actually just output:

Code:
This is the description green leaf


Am I doing something wrong here?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri May 11, 2007 11:30 am   
 
Ok you have two things working here. First off %1 will only capture the first word of your alias parameters... so you really want to use %-1 or better %params.

Your second problem is that by tacking the "1" at the end you are suppressing the command to the output window, and thus the results are just list in the Database Window. Now this may actually be what you want, my guess would be no.

Another thing to consider, if you just want to interrogate the data (as opposed to updating the DB view filter) then consider using the %query function instead.

At any rate I say your code should look more like this.

#var desc {%params}
#dbload herbs
#query (&description = @desc) herbs 0
_________________
Asati di tempari!
Reply with quote
haderach
Newbie


Joined: 10 May 2007
Posts: 4

PostPosted: Fri May 11, 2007 4:31 pm   
 
Thanks for the reply, Tech. I think I'm unable to use your suggestions though. Let me post my full trigger. I am using a regular expression, which is why I use %1 to capture the first group in that regular expression. I also have to supress the output so that I won't get spammed with the record results. My trigger works when it receives this regular expression pattern:

Code:
^\| (.+)\s+\|\s+(\d+)\s+\|


It then executes the following script.

Code:
#var herbdesc {%1}
#var herbcount {%2}
#dbload herbs
#query (&description = @herbdesc) herbs 1
#var herbname {%rec.name}
#var herbpurpose {%rec.purpose}
#var herbmethod {%rec.method}
#var recsret {%numrec( herbs)}
#dbreset
#if (@recsret > 0) {#if (@herbmethod = "") {#sub {| @herbdesc - @herbname - @herbpurpose [@herbcount]}} {#sub {| @herbdesc - @herbname - @herbpurpose (@herbmethod) [@herbcount]}}}


What I receive from the mud looks like this:

Code:
| Herbs                                                        | Qty. |
|---------------------------------------------------------------------|
| bright yellow leaf                                           |    5 |
| brown broad-headed mushroom                                  |    4 |


What I want the client to display is this:

Code:
| Herbs                                                        | Qty. |
|---------------------------------------------------------------------|
| bright yellow leaf - kuko - Increases Awareness [5]
| brown broad-headed mushroom - astaldo - Increases Dis [4]


CMUD doesn't like the brackets in the #sub line even though I really just want to output the variable enclosed in brackets. But that's a different issue. When I don't suppress the output, it still doesn't return the right results.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri May 11, 2007 4:36 pm   
 
Sorry about that.. I guess I should read more carefully.. I thought you were running from an alias. I'll try your code and see what happens.

One thing you can do in the meantime is just for testing purposes, echo @herbdesc to make sure you capture all you want to capture and nothing more.
_________________
Asati di tempari!
Reply with quote
haderach
Newbie


Joined: 10 May 2007
Posts: 4

PostPosted: Fri May 11, 2007 6:10 pm   
 
Thanks Tech! I actually have tested to make sure that @herbdesc contains the right string. That's when I discovered that it seems like everything after the variable simply gets ignored, which may be the source of the problem.

#say {This is the description @herbdesc that I have}

should output "This is the description green leaf that I have" when @herbdesc is "green leaf". However, it just outputs "This is the description green leaf". Everything after the variable just gets truncated. If that's occurring for the #query line that I have, then that explains why it doesn't seem to find anything, but I would think it would throw some sort of syntax error.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat May 12, 2007 12:58 am   
 
Hmmm... sournds like you're picking up an extra character somehow. Check the string legnth and try doing a %trim on it as well and see if you still have the same issue.
_________________
Asati di tempari!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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