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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Jun 26, 2008 8:34 am   

[BUG? 2.29] %string and %quote
 
I'm pretty sure this has been going on for a while, but not sure that anyone really uses it much, and probably why it hasn't been questioned yet. Either that, or I'm totally missing something. However, this is the situation.

I'm using an afk script that shows a message when someone sends me a tell, kindly telling them that I'm not here, and how long I've been gone. Script works perfectly, with one minor flaw:

Unless I quote them, I cannot put special characters in my away message.

Remember that %string converts them to a string (quoted with " "s) and that %quote quotes the actual special characters, I've tried the following:

ft :is away. Reason: %string(%-1)
and
ft :is away. Reason: %quote(%-1)

Neither of them work. In fact, it's like they're both ignored. Sooooo... I ran a couple of tests.

#SAY %string(This (is) a test.)
#SAY %quote(This (is) a test.)

Ran them in zMUD 7.21: The output?

"This (is) a test." (correct!)
This (is) a test. (I'm assuming is correct, although the () don't appear escaped visually).

Ran them in CMUD 2.29: The output?
-- Illegal character in expression: (
This(is)atest.

Knowing that CMUD is stricter, I changed it to:
#SAY %string("This (is) a test.")
#SAY %quote("This (is) a test.")

The results were favorable (sort of). Both returned
This (is) a test.

So, going back to my script, and comparing it to the tests, it appears to me that %string and %quote aren't really doing anything at all. In fact, it appears that the expansion of the values actually comes from the " "s within, not the actual functions.

I think I've also had this same issue in several previous versions, but this has finally bothered me enough to say something about it. Perhaps I should have said something earlier, but I never was too sure if it's a bug or something I'm doing wrong.

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 26, 2008 4:30 pm   
 
When using a literal string on the command line, you MUST enclose the string in quotes if it contains special characters. So CMUD is correct about the illegal ( character in your expression and you are correct that CMUD is stricter and requires the quotes on the command line.

When passing a variable, the %string function just passes it normally and converts the result to a string. The intended use is for converting string lists or database variables into string values, or converting numbers or floating point into strings. For example:

#SHOW (1+2)
-> 3
#SHOW (1+%string(2))
-> 12

%string does not quote anything. The %quote function only quotes the characters listed in the "Special Characters" preferences page (such as @ and % and #, etc). It doesn't quote parenthesis.

So, there isn't any bug here. What you should be doing in your original script is just using %-1 without any special function or conversion. Just create an alias like this:
Code:
#ALIAS afk {ft :is away. Reason: %-1}

and then go into the Settings Editor and turn off the new Parse arguments option. Then when you use the afk alias you can put any special characters that you want.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Jun 26, 2008 9:57 pm   
 
Hmmm, well, I tried your suggestion, Zugg, and then I entered on the command line:

away This is a test (just to test things).

It returned

Error parsing command:
extra ) parenthesis

However, I can still encase it in quotes, and it'll pass just fine. Any other suggestions on this? Or will I need to always encase all my strings in quotes whenever they contain parentheses and whatnot?

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 26, 2008 11:07 pm   
 
Is "away" the name of your alias? Did you go into the Settings Editor and turn off the Parse Arguments option near the bottom of the screen and then click Save? I just tried that here and it worked fine in v2.29. You don't need to encase your string in quotes when Parse Arguments is turned off. In fact, if Parse Arguments is turned off and you put quotes in your string, then the quotes will be passed to the MUD too.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Jun 26, 2008 11:13 pm   
 
Hmmm... I think I located the problem as to why it wasn't working.

I had a local variable defined in the Param box. When I deleted it, it worked without a problem.

But thanks! Love it even more now that I can just do whatever I want without having to quote everything.

Charneus
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 26, 2008 11:19 pm   
 
Hmm, I couldn't get it to fail even with a local variable defined in the Param box. Maybe you could post the exact XML for the one that wasn't working so I can look at it and make sure there isn't some other bug there.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jun 26, 2008 11:22 pm   
 
Do you think you could give a little more details about the local variable. It doesn't sound entirely right that the presence of that should cause things to break. I can see that it would break the Parse parameters option being off. Perhaps if you could post the XML for the alias with the local variable causing it to be broken, Zugg could find a way to either display an error/warning ealier; or we could document a correct usage.

Edit I guess I typing slowly now.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Jun 26, 2008 11:29 pm   
 
Code:
<module name="AwayScript" global="true">
  <uid>{91617ED1-0F4A-414E-82D2-51D915EF4213}</uid>
  <packages>Aardwolf</packages>
  <class name="AwayScript" id="1">
    <class name="AFKAliases" id="2">
      <alias name="away" parsearg="false" id="3">
        <value>#IF (%null( %-1) AND @away=1) {
  "ft :@Chas just returned from "%concat( "@B<(@W=@Y", @afkmsg, "@W=@B)>@C")
  away=0
  catchtells
  #T- "AFKTriggers"
  } {
  away=1
  afkmsg=%-1
  "ft :@Cis away. Reason: "%concat( "@B<(@W=@Y", %-1, "@W=@B)>@C").
  #T+ "AFKTriggers"
  catchtells
  }</value>
      </alias>
    </class>
    <class name="AFKTriggers" id="4">
      <trigger priority="43130" id="5">
        <pattern>^(%w) just sent you a tell.$</pattern>
        <value>#IF %1!=@lastreply {"reply @CHi, "%1"! Sorry, but Charneus is not here right now. Reason: "%concat("@B<(@W=@Y",@afkmsg,"@W=@B)>@C")"."}</value>
      </trigger>
    </class>
    <class name="AFKVariables" id="6">
      <var name="afkmsg" id="7"/>
      <var name="lastreply" id="8"/>
      <var name="away" id="10">1</var>
    </class>
  </class>
</module>


I could have been mistaken, though, and it may just be my own error, but I know that I had unchecked the Parse Argument box, saved it, then tried it right after, and it failed. But then it worked right after I removed the $msg in the Param box. *shrug* If you can't reproduce it, then I'll just assume it was something I did, and isn't a bug at all.

Charneus
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jun 26, 2008 11:52 pm   
 
I tried pretty much every combination of settings I could think of based on what you have provided and couldn't find any failure points when the Parse arguements was off.
_________________
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: Thu Jun 26, 2008 11:52 pm   
 
Hmm, I don't see any $msg argument in the XML that you posted.

Btw, another problem you might want to fix...you have several lines in your script like this:
Code:
"ft :@Cis away. Reason: "%concat( "@B<(@W=@Y", %-1, "@W=@B)>@C").

that is really bad form. Just putting text like this is asking for trouble since CMUD can easily get confused as to whether you want to send this text to the MUD, or return it as a result, or display it to the screen, or what.

While it's ok to be "lazy" on the command line (mostly because of the Smart Command Line feature), within a script you need to be really careful and strict about what you do. If you want to send this to the MUD, then you should really use this:
Code:
#SEND "ft :@Cis away. Reason: "%concat( "@B<(@W=@Y", %-1, "@W=@B)>@C").

you can probably also condense that down to a single %concat since you are mixing an implicit concat at the beginning using the quotes. The cleaner your syntax, the fewer problems you'll have in the future.
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 26, 2008 11:52 pm   
 
How many times can Zugg and Vijilante post at exactly the same time?? Scary.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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