|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: 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 |
|
|
|
SCORNME Novice
Joined: 25 Jul 2004 Posts: 48 Location: aka Falan
|
Posted: 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 |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: 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 |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: 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. |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: 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 |
|
|
|
SCORNME Novice
Joined: 25 Jul 2004 Posts: 48 Location: aka Falan
|
Posted: 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. |
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: 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. |
|
|
|
SCORNME Novice
Joined: 25 Jul 2004 Posts: 48 Location: aka Falan
|
Posted: Wed Jul 28, 2004 3:35 am |
Thanks, LB!
|
|
|
|
|
|