|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Jul 08, 2007 4:05 am
[1.34] #al test {~test %1 %2 %3} - strips spaces |
#al test {~test %1 %2 %3}
Sends "test 123" to the mud instead of "test 1 2 3".
Is there a way to do this without it stripping the spaces? Is this a bug, an intention, or just due to my misuse of ~? |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Sun Jul 08, 2007 7:47 am |
There is a way to do this... though I'm not sure whether the above could still be considered a bug... try:
Code: |
#AL test {#EXEC %concat("~~test ",%1," ",%2," ",%3)}
|
That should work... the concat will explicitly add the spaces in, along with the %n arguments |
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 08, 2007 1:22 pm |
That does work, Thinjon, but this definitely seems like a bug.
|
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Sun Jul 08, 2007 6:42 pm |
Aye, I agree... but figured I'd offer an alternate solution in the meantime :)
For bonus points... if you don't know beforehand how many parameters you need to support:
Code: |
#ALIAS testalias {
$tparam = %1
$pcount = 1
#WHILE (!%null($tparam)) {
#ECHO Param $pcount: $tparam
$pcount = $pcount + 1
$tparam = %eval(%concat("%",$pcount))
}
}
|
Now, of course you could do something more useful than simply echoing the parameters. In your case, you could initialize a local variable with "~test " then concatenate each parameter with a space onto that variable, then #SEND the line :) |
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Jul 08, 2007 10:01 pm |
What I do is replace simple commands to the mud, such as:
dstab <target>
shoot <target> <dir>
flay <target> <defense>
With something more intuitive.
#al dstab {#IF (%null(%1)) {dstab @target} {dstab %1}}
In most cases this is enough, but sometimes a command requires 2 parameters from me, which complexifies things.
#al shoot {
#SWITCH (%null(%2) && %len(%1)>2) {~shoot %1 @dir}
(%null(%2) && %len(%1)<3) {~shoot @target %1}
(%null(%1)) {~shoot @target @dir}
That lets me use a really loose syntax. "shoot zugg". "shoot w" etc. Will all shoot someone, somewhere.
Really though, this is no big deal. I've just renamed those few aliases to "shootT", "flayT" etc. Its still (probably) a bug though. |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Arlie Wanderer
Joined: 09 Jun 2006 Posts: 62 Location: Florida
|
Posted: Sun Jul 08, 2007 10:05 pm |
Instead of listing the paramaters out, you can also use %0 if you don't particularly care about the order they're sent or any of that. This has been working fine for me as a workaround for this issue. Also, if you don't want to have to keep doing the %eval(%concat()) bit, you can put a %char(32) inbetween each argument and it'll send a literal space as well... I guess it's a question of style, no? :D
|
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Jul 08, 2007 10:08 pm |
One quick question, pretty unrelated.
#al test {script referencing the %1-%99 directly}
#al test {$var1=%1;$var2=%2;%var3=%3, etc
<script referencing the assigned local vars>}
I kind of assumed that if I access the parameters directly with %1-99, then this is the same thing as assigning them to local vars and performing functions on the local vars, so far as the speed bonus. I thought local vars were only quicker in comparison to globals.
Is this the case? Or not? |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 08, 2007 10:28 pm |
From the speed tests I've seen, it really depends on the script. The scripts I were running (which were veritably massive - 10000 database operations kind of massive) the difference was a matter of a few milliseconds, a tiny slice of the time the script took. The benefit of local variables in this situation is mostly readability. Also, you can avoid the messy assignment syntax and have CMUD do it for you:
#alias test($var1,$var2,$var3) {whatever} |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jul 09, 2007 6:38 pm |
I've added this to the bug list. The problem is that even with the ~, the parser is detecting the "~test" as a possible alias call and is sending the arguments to the alias instead of formatting them for display to the MUD. So it's just like having:
alias 1 2 3
where 1 is passed into %1, 2 is passed into %2, etc, without the spaces. Anyway, the ~ is supposed to turn this off, but it obviously isn't working as intended. |
|
|
|
|
|