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


Joined: 06 Apr 2004
Posts: 173

PostPosted: Wed Aug 29, 2007 12:17 am   

dereferencing a local variable
 
Is there a way to dereference a local variable?

Code:
#VAR myvar 0


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.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Wed Aug 29, 2007 12:31 am   
 
#var $myvar {whatever}

to assign

@{$myvar}

to view.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Wed Aug 29, 2007 12:33 am   
 
i thought it was:

#VAR %eval($local) {value}
_________________
Discord: Shalimarwildcat
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Wed Aug 29, 2007 12:38 am   
 
Oops, yeah, sorry, shalimar is right. I bet you could use %expand($local), too, etc.
Reply with quote
Zugg
MASTER


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

PostPosted: 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.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: 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
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: 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.
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Sat Sep 01, 2007 12:41 am   
 
got it nevermind

#SAY %eval(%concat("@",$temp))

works
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sat Sep 01, 2007 12:42 am   
 
Don't you mean

#say @{$temp}

?
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: 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)
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sat Sep 01, 2007 4:32 am   
 
I think #var is as convenient as it gets for assigning stuff, sorry.
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: 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.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: 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).
Reply with quote
Fang Xianfu
GURU


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

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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