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
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Tue Jan 20, 2009 7:45 pm   

Local variable expansion problem
 
Tried submitting this through the system, but it doesn't like XML. Local variable substitution doesn't seem to be working correctly when I try to use them to build variable names. This is using CMUD 2.37 on Vista. If you replace all of the named local variables in the examples below with their %1,%2 equivalents, everything works as expected.

Steps to reproduce:

1) Paste in the xml below to create the aliases.
2) From the command line execute the test alias: test part1 part2 some random value
3) Step 2 should have displayed "Setting part1_part2 to 'some random value'" and created the part1_part2 variable with value 'some random value'. The output works as expected, but I get a variable named 4096_4097 created instead of part1_part2.
4) From the command line execute the test1 alias: test1 newvar some other random value
5) Step 4 should have displayed "Setting newvar to 'some other random value'" and created the newvar variable with value 'some other random value'. The output works as expected, but no variable is created at all in this case.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>#show Setting ${pre}_${post} to '%-3'
#var ${pre}_${post} %-3</value>
    <arglist>pre,post</arglist>
  </alias>
  <alias name="test1" copy="yes">
    <value>#show Setting ${varname} to '%-2'
#var ${varname} %-2</value>
    <arglist>varname</arglist>
  </alias>
</cmud>
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Tue Jan 20, 2009 8:22 pm   
 
#var $name value

creates a local variable by design. That means that it won't show up in the settings editor, or anywhere else, because it only exists local to that specific instance of that specific alias. If you need to create a variable using an indirect reference of a local variable, you can use something like

#var %eval($name) value
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Tue Jan 20, 2009 8:41 pm   
 
Ahh that makes sense. I was thinking that the #var command was only used for non-local variables and the #local command was for local variables, but I do see the note in the #var command that it works with local variables as well. However, the %eval trick didn't work for me either, I still get no variable created for some reason.

I also tried changing the first alias to use %concat to build the 2-part name in the #var command

#var %concat($pre, "_", $post)

This results in no variable being created instead of the 4096_4097 variable that I got before.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Tue Jan 20, 2009 9:51 pm   
 
I was unable to reproduce your problems with
#var %concat($pre,"_",$post) test
I was also able to create a variable successfully using %eval.
Make sure you check in different packages, because your variables may be going somewhere unexpected.
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Tue Jan 20, 2009 10:07 pm   
 
It wasn't going to another package since I didn't have any other packages... but I restarted CMUD and it is working fine for me now as well.

Only weird behavior is the 4096_4097 variable which I can get around using the %concat method. Thanks!
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