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
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: 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
Reply with quote
Thinjon100
Apprentice


Joined: 12 Jul 2004
Posts: 190
Location: Canada

PostPosted: 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! :)
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Jul 08, 2007 1:22 pm   
 
That does work, Thinjon, but this definitely seems like a bug.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Thinjon100
Apprentice


Joined: 12 Jul 2004
Posts: 190
Location: Canada

PostPosted: 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! :)
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: 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
Reply with quote
Arlie
Wanderer


Joined: 09 Jun 2006
Posts: 62
Location: Florida

PostPosted: 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
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


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

PostPosted: 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}
_________________
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: 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.
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