|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Tue Jun 13, 2006 2:44 pm
Expanding %1..%99 for variable names |
I've looked at the Knowledge Base article on converting zMUD code to work under CMUD, but I can't find anything that covers this particular situation.
I have aliases that use arguments passed to them to build variable names. They work great under zMUD and really simplify things. In CMUD, it doesn't want to expand the variable, and I'm wondering if there's a way to force it. Various combinations of (), {}, "", and [] have proven futile for me thus far.
Code: |
#ALIAS showvar {#show var is @%1} |
I then set "testing = blah" and try "showvar testing" hoping to see "var is blah" and not "var is @testing"...
Any tips?
(I've found many little quirks, but thought I'd try to work on them one at a time, as I find them. I hope I'm just missing something here.)
Edit: Okay, I kept playing with it some more, and I eventually came up with the solution. I had to encapsulate just the %1 in curly braces to make it expand parameter and evaluate the variable. I could have sworn that was one of the couple dozen variations I had tried, but apparently not. So, for anyone having a similar problem, the answer is thus:
Code: |
#ALIAS showvar {#show var is @{%1}} |
So simple, and yet so elusive. ;) |
|
|
|
Rainchild Wizard
Joined: 10 Oct 2000 Posts: 1551 Location: Australia
|
Posted: Tue Jun 13, 2006 10:47 pm |
I was under the impression that aliases had parameters now, eg:
Code: |
#ALIAS showvar( $var ) { #show var is $var } |
So typing "showvar blah" will echo "var is blah" to the screen.
Digging further into it:
Code: |
#ALIAS showvar( $var1, $var2, $var3 ) {
#show var1 is $var1
#show var2 is $var2
#show var3 is $var3
#show params1 is %params(1)
#show param1 is %param(1)
#show params2 is %params(2)
#show param2 is %param(2)
#show params3 is %params(3)
#show param3 is %param(3)
} |
Typing "showvar blah1 blah2 blah3" will return:
var1 is blah1
var2 is blah2
var3 is blah3
params1 is blah1 blah2 blah3
param1 is blah1
params2 is blah2 blah3
param2 is blah2
params3 is blah3
param3 is blah3
So ... you can use the named variables to access each item, or %params( 1 ) is the equivalent of %-1, and %param(1) is the equivalent of %1.
The old %1 / %-1 and %%1 syntax I think was depreciated, but Zugg will be able to answer that when he gets back. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Wed Jun 14, 2006 3:35 pm |
Thanks for the tip. I'm still seeing that %1..%99 are valid syntax in a lot of cases, but seem quirky in others. I knew that the %% and @@ syntaxes were deprecated. I'll definitely be converting most of my aliases and custom functions over to the new $param syntax, I think. It makes more programming sense to me and just looks better.
My current boggle is in trying to get my custom function to work in an #IF command... |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Wed Jun 14, 2006 5:20 pm |
yeah i have been playing with the param features in my aliases as well its great if you need a temp value .
my # of variables is going to drop considerably since many of them were created for the sole purpose to run something in runtime.
I definatly want to start sharing scripting conversions in the sense that i.e. if you have a problem just as you did more eyes can figure out if its a BUG or a Lack of proper syntax.
I have stuck to the few scripts i really want to mess with because some of these zugg is going to fix when he gets back and i dont want to have (while it might be working) worked around fixes in my scripts that arent optimal i did this in zmud and years later is till hadnt gotten it all cleaned up LOL. |
|
_________________ Confucious say "Bugs in Programs need Hammer" |
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Thu Jun 15, 2006 2:13 am |
Rainchild wrote: |
Code: |
#ALIAS showvar( $var ) { #show var is $var } |
So typing "showvar blah" will echo "var is blah" to the screen.
|
However, if I read Larkin's postcorrectly, he wasn't looking to have it do "var is blah", but rather "var is @blah" where the "@blah" is expanded. I do such "indirect" variables a lot myself |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Thu Jun 15, 2006 3:45 am |
actually he was looking to have it say var is @testing :P which spawns to var is blah because thats the value of @testing :)
I think he was alluding to the fact that command MIGHT be used since its the new format rather than trying to work around the old format. |
|
|
|
|
|