|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: 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>
|
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: 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 |
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: 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. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: 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. |
|
|
|
calesta Apprentice
Joined: 07 Dec 2008 Posts: 102 Location: New Hampshire, USA
|
Posted: 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! |
|
|
|
|
|