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
Bluebear
Beginner


Joined: 10 Oct 2007
Posts: 17

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


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

PostPosted: 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 >.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: 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
Reply with quote
Bluebear
Beginner


Joined: 10 Oct 2007
Posts: 17

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


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

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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