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

Play RetroMUD
Post new topic  This topic is locked: you cannot edit posts or make replies.     Home » Forums » CMUD Beta Forum
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 2:31 am   

[2.16 Pro] %db not passing/parsing params correctly.
 
Given the following code:
Code:

<class name="Rift" id="272">
  <var name="riftmap" type="Record" id="285">crystal pentagon=pentagon|crystal torus=torus|goldenseal root=goldenseal|sidewinder skin=sidewinder skin|leather=leather|gold=goldbar|prickly pear=pear|crystal polyhedr=polyhedron|platinum=platinum|kelp=kelp|ginseng root=ginseng|crystal egg=egg|crystal pyramid=pyramid|red ink=redink|steel=steel|crystal diamond=diamond|kola nut=kola|coal=coal|ginger root=ginger|black cohosh=cohosh|lady's slipper=lady's slipper|weed=weed|obsidian=obsidian|irid moss=moss|bloodroot leaf=bloodroot|gems=gems|echinacea=echinacea|ice=ice|green ink=greenink|kuzu root=kuzu|rope=rope|eagle's feather=feather|myrrh gum=myrrh|sileris=sileris|crystal cylinder=cylinder|venom sac=venom sac|yellow ink=yellowink|skullcap=skullcap|bayberry bark=bayberry|crystal polyhedron=polyhedron|crystal sphere=sphere|silver bar=silver|crystal spiral=spiral|slippery elm=elm|prickly ash bark=ash|piece of stag's horn=horn|diamond dust=dust|crystal cube=cube|bone=bone|piece of stag's=horn|crystal disc=disc|lady's slipper root=lady's slipper|gold ink=goldink|lifestone=lifestone|blue ink=blueink|hawthorn berry=hawthorn|valerian=valerian|iron=iron|lobelia seed=lobelia|wood=wood|bellwort flower=bellwort|cloth=cloth|purple ink=purpleink</var>
  <trigger priority="2970" regex="true" id="297">
    <pattern>\s+\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)|)|)$</pattern>
    <value>#ADDKEY rift %db(@riftmap,%2) %1
#ADDKEY rift %db(@riftmap,%4) %3
#ADDKEY rift %db(@riftmap,%6) %5</value>
  </trigger>
</class>


The regex trigger:
Code:
\s+\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)|)|)$

Captures the following:
Quote:
[1529] bayberry bark [1228] bellwort flower [1568] black cohosh

as:
%1 = 1529
%2 = bayberry bark
%3 = 1228
%4 = bellwort flower
%5 = 1568
%6 = black cohosh

and this aspect of this triggers work normally. Now let it be given that in the variable riftmap above:
Code:

Bayberry bark=bayberry
Bellwort flower=bellwort
Black Cohosh=Cohosh


The following code which is the value for the trigger above:
Code:

#ADDKEY rift %db(@riftmap,%2) %1
#ADDKEY rift %db(@riftmap,%4) %3
#ADDKEY rift %db(@riftmap,%6) %5


Does NOT access the Riftmap variable correctly because %db is still requiring quotation marks (" ") around a two word key in order to return its value. This presents a problem because any quotes I put around %2 cause it to be literal per the new operation of %1,%2,%3 etc.

I've tried various solutions such as temp variables, inserting quotes into the value manually and putting ~"%2 ~" as a param for %db

None of these solutions work and it is my understanding that there shouldn't be any "solution" required but that %2 should be able to be passed through %db without any problems.
_________________
Achaea
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 12, 2007 2:57 am   
 
Confirmed with something simpler
Code:
#ADDKEY a {b c} {1};#TRIGGER {b c} {#SHOW %db(@a,%1)};#SHOW "b c"
Yields the same null result.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Dec 12, 2007 5:24 am   Re: [2.16 Pro] %db not passing/parsing params correctly.
 
As an aside, your regex can be neatened slightly:
Code:
\s+\[\s*([0-9]+)\]([ \'a-z]+)(?:\s+\[\s*([0-9]+)\]([ \'a-z]+))?(?:\s+\[\s*([0-9]+)\]([ \'a-z]+))?$

I don't know about you, but I find that format easier to read.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 6:16 am   
 
Not sure exactly what that line will do, as I got the trigger from a friend, but I think the point of it being written that way is that there are not always three items per line, sometimes two and sometimes only one item may appear.
_________________
Achaea
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Dec 12, 2007 11:26 am   
 
Yes. If, for the sake of simplicity, we replace the construct \s+[\s*([0-9]+)]([ \'a-z]+) with pat and the syntax for non-capturing brackets, (?:stuff) with (stuff), the different becomes easier to understand:

pat(pat(pat|)|)$
pat(pat)?(pat)?$

The former example is using the list syntax. The regex (one|two) will match either one or two, so the regex (pat|) will match either pat or nothing. Functionally, this is the same as the syntax (pat)? which means "zero or one of the preceding item" - the preceding item in this case being pat. In fact, this could probably be simplified even further:

(pat){,3}$

the syntax {,3} means "match up to three of the preceding item", but probably needs checking to make sure the captures work as intended.

Anyhow, the difference is pretty much a matter of personal taste - I find the one I suggested to be easier to understand than the one you posted, and the {,3} one, assuming it works as intended, to be even simpler.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Dec 12, 2007 5:27 pm   
 
Vijilante: You are missing () parens in your trigger:
Code:
#ADDKEY a {b c} {1};#TRIGGER {b c} {#SHOW %db(@a,%1)};#SHOW "b c"

Notice that the trigger pattern doesn't have any () so the %1 doesn't expand to anything. If you use a pattern of "(b c)" then it seems to work fine for me in v2.17.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 12, 2007 6:17 pm   
 
Bah, I should just give up after a certain time of day; or maybe I shouldn't check on such things when I am really working on other scripting and testing. I always seem to make such dumb mistakes at such times.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Dec 12, 2007 6:36 pm   
 
So anyway, can anyone reproduce the original poster's problem? As Vjilante's fixed example shows, two-word keys seem to be working fine. So I cannot reproduce the problem with this.
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 6:46 pm   
 
Just reproduce it in the command line, or use my code.

Who cares what Vijilante posted, it's irrelevant because he didn't code it right, my code functions and produces this problem.

Make a variable with a two word key, then do #show %db(@yourdbname,keyword1 keyword2) and you'll see the problem
_________________
Achaea
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 6:54 pm   
 
Open CMUD
Press escape
enter the following at the command line:
#addkey Riftmap "Bayberry Bark" Bayberry
#show %db(@riftmap,bayberry bark)
You'll see nothing
Now enter
#show %db(@riftmap,"bayberry bark")
and you'll see
bayberry
outputted.

This is what I'm talking about, the same thing happens in the code for my trigger, %2 is expanding fine inside %db(@riftmap,%2) but the actual code for %db won't parse multi-word parameters unless they are in quotes, which I can't do because of the way quotes are handled in CMUD.
_________________
Achaea
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Dec 12, 2007 7:24 pm   
 
Code:
#show %db(@riftmap,bayberry bark)

That is correct. You need to put "" or {} around string values to preserve any internal spaces. This is a fundamental requirement for all strings in CMUD. But this doesn't apply to what you originally posted because you used:

%db(@riftmap,%2)

and the %2 works properly when it contains spaces.

Here is another example:
Code:
#ALIAS showkey {#SHOW %db(@riftmap,%1)}
showkey "bayberry bark"

that displays "bayberry" as it should.

So this isn't a bug. String arguments in CMUD must be enclosed in quotes or {} to preserve spaces.
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 7:33 pm   
 
It just seems that making %db require quotes around two-word parameters is the antithesis of what you were trying to do by getting rid of the need for quotes around %1.
It's a hell of a hassle to get those quotation marks around %1 without negating parameter expansion just because one function requires it.
_________________
Achaea
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Dec 12, 2007 7:42 pm   
 
One function doesn't require it - this behaviour's the same for all functions. If it's a string and has spaces, it needs quotes. If it's a variable reference, it doesn't. There's no ambiguity here.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 7:59 pm   
 
Evil or Very Mad
Then how the hell do I add quotes to %2 without causing it to be passed through %db as literally "%2"?
_________________
Achaea
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Wed Dec 12, 2007 8:21 pm   
 
The problem you are having here is nothing to do with quotes around %2.
The problem is that your regex doesn't work as you think it does

If you change the trigger action to
#SAY First: -%1-%2-
#SAY Second: -%3-%4-
#SAY Third: -%5-%6-

You will find the leading spaces from your matches are not being removed. What you are actually looking for in the database is " bayberry bark", which quite correctly is returning a null value because no such entry exists with a leading space. You want to start using %trim to fix that problem.
You'll also find that the regex isn't matching all 3 sets, it's skipping the first entirely. I've not looked at the pattern in any detail, but I'm sure you can fix that.

So, if you change your #ADDKEY to
#ADDKEY rift %db(@riftmap, %trim(%2)) %1
#ADDKEY rift %db(@riftmap, %trim(%4)) %3
#ADDKEY rift %db(@riftmap, %trim(%6)) %5

You will find most of your problems will go away.

Lastly, please be a bit more mindful of your tone when posting, you're being a bit antagonistic.
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Wed Dec 12, 2007 8:43 pm   
 
Your regex is easily fixed too actually

The one you have
Code:
\s+\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)(?:\[\s*([0-9]+)\]([ \'a-z]+)|)|)$

forces whitespace at the start of a line - in your example there was no whitespace, so replace the \s+ with a \s* to allow for that
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Vesence
Beginner


Joined: 12 Mar 2006
Posts: 22

PostPosted: Wed Dec 12, 2007 9:02 pm   
 
Yeah, I finally figured out the issue with extra spaces, this wasn't happening when the code was used in zmud so I wasn't looking for it.

As for being antagonistic, it just ticks me off when I post something, then it's simplified by someone else and that's done incorrectly, then when that's discovered Zugg refers to me merely as the opening poster (I have a name thank you) and that he can't recreate my problem when it's right there in the code and he gives me a solution that is inapplicable because it's given as an alias when I can't control that explicitly the input coming from a trigger.
_________________
Achaea
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Wed Dec 12, 2007 9:19 pm   
 
You're welcome Rolling Eyes
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 12, 2007 9:34 pm   
 
Quote:
Zugg refers to me merely as the opening poster (I have a name thank you)

Quote:
then it's simplified by someone else and that's done incorrectly
Hrm, *looks over to the left*. Yep I have a name too. I guess I should be irritated as well, oddly I am not. I don't much mind being called "someone else" by you. Yes, I tested it incorrectly. Yes, that wasted Zugg's time. Yes, I went on what you said was the problem. Yes, Guinn actually correctly diagnosed the problem and you never said thank you. Finally yes, further posts in this thread are a waste of all of our time.

Quote:
Lastly, please be a bit more mindful of your tone when posting, you're being a bit antagonistic.
I was quite happy to leave it at that and quietly wish Guinn a thank you, but I guess that is not meant to be. Guinn, thank you for your thoughtful request to the 'original poster'.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Dec 12, 2007 11:36 pm   
 
Just in case any other readers are confused about this, CMUD is working just like any other language here. For example, in Visual Basic, you would do this:
Code:
msgbox "This message has spaces in it"
myvar = "This is another message"
msgbox myvar

Notice that when you call msgbox with a literal message, you have to put " quotes around the string. But when you call it with the myvar variable, as in the last line, you don't put any quotes around the variable name. And notice that when the message boxes are displayed, none of them have quotes in the message that is displayed.

In CMUD, %1..%99 are *variables*, just like @myvar would be.

The problem was that zMUD had a very loose parser and it didn't require the quotes when calling a function with a literal string. In a normal programming language, like Visual Basic, you'd actually get an ERROR if you didn't put quotes around the string value. CMUD doesn't generate an error, because it is trying to preserve as much compatibility with zMUD as possible. So it retains the value, but the spaces get stripped.

The reason the spaces get stripped outside of quotes is that many people add spaces to make their scripts more readable. For example:
Code:
#SHOW %dbvar( @var, key)

OK, so in the above line, should the key be " key" or just "key"? Obviously you want it to be just "key" without the leading space. The leading space is added just to make the script more readable.

In zMUD, there were many cases where it *would* add the space and use " key" and cause all sorts of strange results. zMUD contained kludges to strip these spaces in most cases, but it wasn't intended to be used with multiple words without the quotes.

Anyway, while this change may seem "weird" to experienced zMUD users, it will seem natural to new users who haven't used zMUD before but are used to how things work in most all other programming languages in the world. The fact is that it is zMUD that had the problem by allowing this poor syntax.
Reply with quote
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.     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