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
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Oct 11, 2007 4:49 pm   

%expand
 
I'm having trouble with expanding variables. I'm on version 1.34, but I don't see anything in the changelist for 2.x related to this.

The %expand documentation has the following example:
#VAR zuggsoft "Zugg's virtual home."
#VAR email "zugg@zuggsoft"
#SHOW w/o expand: @email

displays (according to the documentation):
w/o expand: zuggZugg's virtual home.

What I actually get is:
w/o expand: zugg@zuggsoft


The documentation continues:
#SHOW with expand: %expand(@email,1)

displays:
with expand: zugg@zuggsoft

This is what I get too. Now, I would expect that %expand(@email) would now produce "Zugg's virtual home". But it doesn't. It gives "zugg@zuggsoft". I've tried all kinds of variations, including %expand(%expand(@email)), but I cannot get the inner variable to expand.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Oct 11, 2007 4:56 pm   
 
I should update the help file for this.

The difference is that you have "" quotes in your #VAR line, which makes CMUD treat the result as a literal string, which does not expand further.

If you change it to use {} instead of "", then it will be stored as an "expandable" string. So, this would work:
Code:
#VAR zuggsoft "Zugg's virtual home."
#VAR email {zugg@zuggsoft}
#SHOW with expand: %expand(@email)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Oct 11, 2007 5:00 pm   
 
Hmm, no, I was wrong. When you use the {} then the @zuggsoft is expanded right away by the #VAR command. So that's not right either. Looks like there is a bug in %expand. I'll take a look at it.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Thu Oct 11, 2007 5:09 pm   
 
This is because CMUD's parser is now smarter. It understands that when you surround something with quotes, it's a string. Since the literal string "zugg@zuggsoft" is stored in the variable, that's the literal string that's displayed by default.

To get the zuggZugg's virtual home result, use %eval(@email) instead, which will evaluate the string inside @email.

I'm not sure if this is just a documentation problem between zMUD and CMUD or if there's a problem with %expand - I couldn't get it to work using %expand(@email,2) or anything, so it seems like a bug. Not that %expand sees much use since %eval works just as well, anyway.

EDIT: Ninja'd by Zugg Sad Still, use %eval for now.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Oct 11, 2007 5:15 pm   
 
Hm. Yes, I see. It is smarter now about what is a literal, which should not be expanded. But that basically means that %expand is useless. It can only ever do a single level of expansion. But %eval does work. I'll put that into my code. Thanks!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Oct 11, 2007 5:17 pm   
 
I spoke too soon. It doesn't quite work. It gives: zuggZugg'svirtualhome, removing the spaces
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Thu Oct 11, 2007 5:39 pm   
 
I think that problem's been fixed by 2.05.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Oct 11, 2007 6:25 pm   
 
Oh good! My scripts have run into enough problems solved in 2.05 that it's time for me to try it. Thanks!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Oct 11, 2007 7:08 pm   
 
You might wait until 2.06 is released on Friday. It solves the serious trigger problems in 2.05.
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