|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Wed Aug 29, 2007 12:17 am
dereferencing a local variable |
Is there a way to dereference a local variable?
Code: |
#ALIAS test {
$local = myvar;
//use $local as a reference to myvar
*$local = 1 // I would like to assign myvar = 1 using $local
#SAY $local //outputs myvar
#SAY *$local //outputs 1
} |
I'm using * as in the C++ dereference, but I don't know if it's possible to do in CMUD. |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Wed Aug 29, 2007 12:31 am |
#var $myvar {whatever}
to assign
@{$myvar}
to view. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Wed Aug 29, 2007 12:33 am |
i thought it was:
#VAR %eval($local) {value} |
|
_________________ Discord: Shalimarwildcat |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Wed Aug 29, 2007 12:38 am |
Oops, yeah, sorry, shalimar is right. I bet you could use %expand($local), too, etc.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Aug 29, 2007 7:52 pm |
You don't even need the %eval. I think that even
#VAR ($local) {value}
will work. The () tells CMUD to evaluate an expression. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Wed Aug 29, 2007 8:07 pm |
I've had to use %eval(). () was not enough.
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Sat Sep 01, 2007 12:27 am |
I still cant figure out how to do the #SAY operation.
#VAR varname 1
$temp = varname
#SAY %eval($temp)
outputs:
varname
%expand fails with temp variables.
not sure how else to do it. |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Sat Sep 01, 2007 12:41 am |
got it nevermind
#SAY %eval(%concat("@",$temp))
works |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sat Sep 01, 2007 12:42 am |
Don't you mean
#say @{$temp}
? |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Sat Sep 01, 2007 1:21 am |
yes actually that works wonderfully!
is there a convenient way to assign values to the target of $temp?
some sort of %eval($temp) = 1
(this doesn't work however) |
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sat Sep 01, 2007 4:32 am |
I think #var is as convenient as it gets for assigning stuff, sorry.
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Sun Sep 02, 2007 1:27 am |
yeah the only problem with using the #VAR statement is that I'd have to know what the default value for the variable was before I'd overwrite it... and I don't think there's a function that retrieves that information.
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sun Sep 02, 2007 1:41 am |
If you just use
#var whatever {value}
it won't overwrite any default that whatever has (if it does indeed have one). |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Sep 02, 2007 2:04 am |
Gamma Ray's right, the default isn't changed if it's not specified.
You can access the default using CMUD's COM interface, which isn't documented, but is very similar to zMUD's. It'll look something like %session.GetVar(varname).Default, but I haven't tested that. There are other posts on the forums about it, anyway. |
|
|
|
|
|