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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Tue Jul 27, 2004 1:23 am   

Variable Within A Variable
 
I'm trying to create a variable with a name that contains a variable. I've been able to do this in the past I think, but I can't remember how. After two hours of searching, I figured I'd ask you folks. Maybe you can refresh my memory. :)

Trying something like:

#var @charname_worth {123456}

Hoping to create a variable named "Rahve_worth", that equals the value given.

I thought I remembered doing it like this, in the past:

#var {@charname}_worth {123456}

But that didn't quite work. Any ideas folks..?
_________________
Fat Tony
Reply with quote
SCORNME
Novice


Joined: 25 Jul 2004
Posts: 48
Location: aka Falan

PostPosted: Tue Jul 27, 2004 6:20 am   Re: Variable Within A Variable
 
Looking at the Help files for Parsing, would this work?

#VAR @{charname}_worth 123456
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Tue Jul 27, 2004 8:08 am   
 
Actually that does work, but for some reason it creates the variable WITH the brackets surrounding it.

Ex - that variable is labelled {Rahve}_worth

Any idea how I can get rid of the {}'s from the final product..?
_________________
Fat Tony
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Tue Jul 27, 2004 8:29 am   
 
#var [@charname]_worth {123456}

[] forces the command to expand @Charname before creating the variable. @{charname} shows #var where the name of the variable ends.
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Tue Jul 27, 2004 9:05 am   
 
Cool, that did work, thank you. I have a very complicated command I use to calculate my worth and tax etc on my MUD, and I'm trying to get this to create a variable set for each char that gets the worth told to them. It works just fine with the @charname's stripped, but I can't get it to parse the NEW variable name, including the char's name. Any ideas how I can do this..?

#say Worth at last EW: %eval( (@{charname}_st_worth) / 1000000)M - After Tax: %eval( (@{charname}_st_taxworth) / 1000000)M - Tax Total: %eval( (@{charname}_st_tax) / 1000000)M ~{@floatingpoint_percent( %eval( 100 * %float( (@{charname}_st_tax)) / %float( (@{charname}_st_worth))))~%~}

The [@charname]_worth set was barked about by the settings editor, and didn't seem to work in the command line either.
_________________
Fat Tony
Reply with quote
SCORNME
Novice


Joined: 25 Jul 2004
Posts: 48
Location: aka Falan

PostPosted: Tue Jul 27, 2004 9:45 am   
 
Danlo wrote:
#var [@charname]_worth {123456}

[] forces the command to expand @Charname before creating the variable. @{charname} shows #var where the name of the variable ends.


Another good to know. Especially since the Help files say [] evaluates and

Quote:
if @test contains the string abc, then @{test}def expands to abcdef.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Jul 27, 2004 3:31 pm   
 
When in doubt, test for yourself. After a couple minutes of experimentation, I have the following results. Variable names and values were checked by entering just the #VAR command. All experiments were done both from the command line and from an alias, with identical results. Except for @charname, variables were deleted after each test.

#VAR charname Rahve
Creates a variable named charname with value Rahve

#VAR @charname_worth 123456
Does nothing

#VAR {@charname}_worth 123456
Creates a variable named {Rahve_worth} with value 123456

#VAR @{charname}_worth 123456
Creates a variable named Rahve_worth with value 123456
NOTE: The variable with the brackets surrounding it was a holdover from your earlier attempts, not from this syntax.

Additional experiments:
#VAR [@charname]_worth 123456
Creates a variable named Rahve_worth with value 123456

#VAR <@charname>_worth 123456
Creates a variable named Rahve_worth with value 123456

I probably wouldn't use any of these. Record variables are simpler.
#ADDKEY worth {@charname} 123456
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
Reply with quote
SCORNME
Novice


Joined: 25 Jul 2004
Posts: 48
Location: aka Falan

PostPosted: Wed Jul 28, 2004 3:35 am   
 
Thanks, LB!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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