|
Bluebear Beginner
Joined: 10 Oct 2007 Posts: 17
|
Posted: Mon Jan 28, 2008 4:12 pm
Double expansion of variables |
Hi again,
Thanks go to people that have helped with previous problems.
I have imported a settings file from zmud into cmud that relies on hundreds of variables that are stored within other variables.
A contrived example-
#Var lowerlayer "final result"
#Var higherlayer "@lowerlayer"
Zmud used to fully expand @higherlayer all the way to 'final result' before sending to the mud.
Cmud dosnt and neither can we use brackets anymore for double expansion, so if I use @higherlayer Cmud sends '@lowerlayer' to the mud. I have tried using eval() but that actually strips spaces from the bottom variable ie it sends 'finalresult' instead of 'final result'
How can I ask Cmud to expand variables to the bottom layer before sending to the mud?
Thanks |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 28, 2008 5:05 pm |
#var higherlayer {@lowerlayer} should work fine. Simple test:
#var lowerlayer "hello!"
#var higherlayer {@lowerlayer}
#say @higherlayer
prints "hello!" as you'd expect. In CMUD, you should use quotes "" to surround literal strings. These are strings that won't be expanded. If you want variables (beginning with @) and functions (beginning with %) to be expanded, you should use braces {}, which are used to tell CMUD that the result is still a string, but should be expanded first. Brackets () are used to indicate an expression, which'll be evaluated, which is slightly different to expansion - evaluation normally involves a true-or-false test with an operator like = or >. |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Mon Jan 28, 2008 5:28 pm |
In most cases
#Var higherlayer @lowerlayer;
(or even just higherlayer=@lowerlayer syntax)
will work fine. |
|
Last edited by Arde on Tue Jan 29, 2008 5:25 am; edited 1 time in total |
|
|
|
Bluebear Beginner
Joined: 10 Oct 2007 Posts: 17
|
Posted: Mon Jan 28, 2008 5:56 pm |
Thank you.
I see the difference between #var example "" and #var example {} now and I have a better understanding of literals.
I suppose the only real reason to use "" over {} is when you have special characters in the variable. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 28, 2008 6:11 pm |
Indeed. In zMUD, using
#var hp "%1"
is ambiguous - do you mean the literal string "%1" or the contents of the variable %1? In CMUD, "%1" means the literal string and {%1} expands the variable. |
|
|
|
|
|