Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Wed Jun 10, 2009 8:05 pm   

Local Varibles and #var
 
I think I found a few more local varible parsing errors when used with #var

1) From blank session paste following code
Code:
<alias name="testlocal" id="1135">
  <value>#local $var
$var = "test"
#print local is now $var
$var = %concat($var,"test1")
#print local is now $var
#var {$var} {test}
#print local is now after #var {~$var} {test} : $var
#print varible with local name is now : @{$var}

#print
$var = %concat($var,"test2")
#print local is now $var
#var $var {test}
#print local is now after #var ~$var {test} : $var
#print varible with local name is now : @{$var}

#print
$var = %concat($var,"test3")
#print local is now $var
#var %concat($var) {test}
#print local is now after #var ~%concat~(~$var~) : {test} $var
#print varible with local name is now : @{$var}</value>
</alias>


2) run testlocal variable

The first 2 global variables are never created, although I would expect them to be, and the value of the local variable is changed.
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 11, 2009 12:15 am   
 
This is actually the correct operation of the #VAR command with local variables. When you reference the local variable directly (like with {$var} or $var in your first two examples), you are modifying the actual local variable itself and not the variable pointed to by the contents of the local variable (indirect assignment). The only way to do indirect assignment with #VAR and local variables is using a function, like in your third example. Using something like %string($var) also works.

Indirect variable assignment like this is a very advanced topic and it's not something I expect novice scripters to be using. Advanced scripters just need to learn the specific syntax for doing it. For novice scripters, then expect:

#VAR $local value

to assign "value" to the local variable...they don't understand the concept of indirect variable assignment. The issue only arises at all because local variables have a simplified syntax where you *always* use the $ in front of the variable name. With normal CMUD variables, the @ is only used to reference the value of a variable rather than the name of the variable itself. Local variables don't have that distinction, so it's sometimes tricky to mix local variables into a syntax that was created to support normal variables.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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