|
eupher Apprentice
Joined: 18 Jan 2001 Posts: 116 Location: USA
|
Posted: 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 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
TaisharMalkier Novice
Joined: 28 Sep 2001 Posts: 45 Location: USA
|
Posted: 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. |
|
|
|
eupher Apprentice
Joined: 18 Jan 2001 Posts: 116 Location: USA
|
Posted: 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 |
|
|
|
Troubadour GURU
Joined: 14 Oct 2000 Posts: 556 Location: USA
|
Posted: 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 |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: 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~"" |
|
|
|
eupher Apprentice
Joined: 18 Jan 2001 Posts: 116 Location: USA
|
Posted: 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 |
|
|
|
|
|