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
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Tue Jan 08, 2002 2:30 am   

escaping ampersand (&) in a script
 
I have an alias that needs to send strings containing ampersands to the mud. Assuming I want to keep & as the special db character and leave it enabled, is there any way to escape it in the alias? The mud I play uses & as a special character to color messages.

Basic example:

#alias myalias {gossip &G this is green}

I tried ~ but that didn't seem to help me.

Thanks,
Eupher
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Jan 08, 2002 2:58 am   
 
well, I know using the %char(&) method will guarantee it not getting used as the reference character. That's probably not the best way to do it, though. Maybe quotes? "&" or even "&G"?

li'l shmoe of Dragon's Gate MUD
Reply with quote
TaisharMalkier
Novice


Joined: 28 Sep 2001
Posts: 45
Location: USA

PostPosted: Tue Jan 08, 2002 3:04 am   
 
This seemed to work for me.

#alias test {say ~&G This is Green}
test

Shows :
&G This is Green

If this doesnt work, let me know.
Also check your settings of Special Characters. I dont know if that would make and difference, but it may.

Contain rather than hurt.
Hurt rather than maim.
Maim rather than kill.
Kill rather than be killed.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Sat Jan 12, 2002 3:52 am   
 
Ok, my example wasn't entirely accurate. :)

What I'm trying to do is create variables with color codes as values... color codes being represented by a single letter preceded by an ampersand. Then I want to be able to insert these color variables into other variables.. copying/appending at will... and at some point be able to send the result to the mud.

Example (second draft):

mycolor = ~&Y
greeting = {Hello there @{mycolor}mister!}
say @greeting


In a nutshell.. I'd like to be able to define color codes in variables and use those variables freely... and always end up with the intended code no matter how many times the variable is evaluated.

Thanks again,
Eupher
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sat Jan 12, 2002 8:46 am   
 
Use the %expand function to prevent the parser from trying to expand &Ymister.

mycolor = ~&Y
greeting = {Hello there %expand(@mycolor, 1)mister!}
say %expand(@greeting, 1)

Troubadour
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jan 12, 2002 10:43 am   
 
The much simple or more complex solution depending on your total scripts is to turn off the & special character. If you do not use the database at all then that will have your all set instantly. If you do then you may wish to evaluate which is more efficient for you, turning it off in general and turning it on only for those trigger that use it (using #DEFAULT and #NODEF}, or redefining it to another character and updating those scripts that need it.

Of course the yet more ugly solution that will prevent any level of expansion I could test was to define your variable like this:
mycolor="~"&Y~""
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Tue Jan 15, 2002 2:38 am   
 
Thanks much for the suggestions. Since I have control over the class I'll be sharing, yet no control (or desire to control) the end user's preferences, I chose the %expand() route and it works great.

Thanks again for the help.

Eupher
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