|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Wed Sep 10, 2008 8:31 pm
%query problem |
hi
This is the output from mud:
#SH You still have to kill * a sweaty carpenter ~(Three Pillars of Diatz~)
#SH You still have to kill * a magician's apprentice ~(Three Pillars of Diatz~)
#SH You still have to kill * an orc ~(Ruins of Diamond Reach~)
#SH You still have to kill * city guard ~(Imperial City of Reme~)
This is my trigger:
Code: |
^You still have to kill ~* (*) ~((*)~)$ |
With this patttern:
Code: |
walkzone = %replace( %2, "'", "''")
#VAR cp_walkroom %additem( %db( %query( &name = %1 && &zone = @walkzone), roomid), @cp_walkroom) |
the trigger works, but I cant get the pattern to work, I know all the output is in my database, like if I do:
Code: |
#sh %db(%query(&name = 'a sweaty carpenter' && &zone = 'Three Pillars of Diatz'), roomid) |
it show 6236 wish is the right room id |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Sep 10, 2008 9:38 pm |
The %query function requires a string argument. So you should be using:
Code: |
#VAR cp_walkroom %additem( %db( %query( %concat( "&name = '",%1,"' && &zone = '",@walkzone,"'")), roomid), @cp_walkroom) |
That will also put the needed single ' quotes around the %1 and @walkzone that you need for the query to work like in your #show example. Parsing of function arguments is much more strict in CMUD than it was in zMUD. |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Thu Sep 11, 2008 5:05 pm |
nope I cant get it to work, the @cp_walkroom is empty
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Sep 11, 2008 10:35 pm |
Then something else is wrong. Try adding some debug statements to display the value of the query string. For example:
Code: |
$QueryStr = %concat( "&name = '",%1,"' && &zone = '",@walkzone,"'")
#SHOW {QueryStr is: $QueryStr}
#SHOW {Result is: %query( $QueryStr)}
$SHOW {Roomid is: %db( %query( $QueryStr), roomid)}
#VAR cp_walkroom %additem( %db( %query( $QueryStr), roomid), @cp_walkroom) |
To try each step to determine where the problem is. If your #SHOW command worked above, then you should be able to track down the problem. |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Fri Sep 12, 2008 3:02 pm |
This is the output from your little script:
Code: |
QueryStr is: &name = 'a sweaty carpenter' && &zone = 'Three Pillars of Diatz'
Result is:
Roomid is: 13258
QueryStr is: &name = 'a magician's apprentice' && &zone = 'Three Pillars of Diatz'
Result is:
Roomid is: 13258
QueryStr is: &name = 'an orc' && &zone = 'Ruins of Diamond Reach'
Result is:
Roomid is: 13258
QueryStr is: &name = 'city guard' && &zone = 'Imperial City of Reme'
Result is:
Roomid is: 13258 |
And the variable:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="cp_walkroom" type="StringList" copy="yes">13258|13258|13258|13258</var>
</cmud> |
I dont know why its picking the roomid 13258 cus thats:
name: a bartender zone: Onyx Bazaar roomid: 13258 |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Sat Sep 13, 2008 7:23 pm |
ok I got this to work:
Code: |
#SHOW %db( %query( "&name = "%1""), roomid) |
But I cant get it to work with both name and zone:
Code: |
SHOW %db( %query( "&name = "%1" && &zone ="%2""), roomid) |
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Sep 15, 2008 5:08 pm |
OK, sorry, the problem is with the quotes. You need double " quotes around the name and not " single quotes. To get a " quote within a quoted string, you need to double it. So this can get a bit hard to read, but it would be something like this:
Code: |
$QueryStr = %concat( "&name = """,%1,""" && &zone = """,@walkzone,"""") |
or in your #SHOW example:
Code: |
#SHOW %db( %query( "&name = """%1""" && &zone = """%2""""), roomid) |
although it's better to use the explicit %concat function instead of trying to rely on the implicit concat that you are using in your #SHOW statement.
If that doesn't work, then it's possible you need extra parenthesis to group the two tests, like:
Code: |
$QueryStr = %concat( "(&name = """,%1,""") && (&zone = """,@walkzone,""")") |
|
|
|
|
Michael Nelson Novice
Joined: 03 Oct 2005 Posts: 36
|
Posted: Sun Oct 12, 2008 9:50 pm |
This does not work for me, I am searching the boards but as far as I can tell there is no way to get CMUD to expand its parameters.
|
|
|
|
chosig Novice
Joined: 20 Apr 2008 Posts: 39 Location: Sweden
|
Posted: Tue Oct 21, 2008 6:15 am |
Bump on this...
I've tried all variants I can think of, but I can't get %1 to expand in CMUD...
Small example:
Code: |
Doesn't work:
#SHOW %db( %query( %concat("&name = """,%1,""""), roomid)
Works:
#SHOW %db( &name = "Roomname"), roomid)
|
Putting the query in a @variable or $variable doesn't work either, it's like as %query refuses to expand variables... |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Oct 21, 2008 4:25 pm |
As reported in other thread, it was discovered that the %query function doe not expand it's argument at all. So no functions or variables work with it properly right now. This will be fixed in the next version. Until then, you need to construct the query command and then use #EXEC to run it, like this:
Code: |
$str = %concat("#SHOW %db(%query( &name = """, %1, """), roomid)")
#EXEC $str |
or something like that. |
|
|
|
|
|
|
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
|
|