Modifying a variable variable

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
Venatius
Dragon
Posts: 256
Joined: Mon Feb 16, 2009 7:12 pm

Modifying a variable variable

Post by Venatius »

This seems like it should be simple, but I'll be darned if I can figure out how. I'm looking for a way to handle doing a variable assignment for a variable that is, itself, variable. Here's a quick and dirty example:

Code: Select all

[h: Strength = 10]
[h: statName = "Strength"]
The goal is to set the Strength variable to 20 instead, but only by referring to the value stored on statName (so that, for example, one could swap in the name of a different variable as needed).

Obviously, doing [statName = 20] will just change the statName variable. [eval(statName) = 20] gets a little closer, as it actually returns the value of the variable named in statName, but it doesn't assign anything - it just returns 10, seemingly ignoring the equals sign and so forth. I feel like there's got to be a way to do this, and it's something simple enough. (I'm a little surprised that eval(statName) returns 10 and not "Strength".) Any thoughts on what I'm missing here, please?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Modifying a variable variable

Post by aliasmask »


User avatar
Venatius
Dragon
Posts: 256
Joined: Mon Feb 16, 2009 7:12 pm

Re: Modifying a variable variable

Post by Venatius »

aliasmask wrote:You can use Wiki: set() or Wiki: setProperty().
Well I'll be a monkey's uncle! I knew there had to be some kind of simple function for this. Added to the above example code, [set(statName, 20)] does indeed set the Strength variable to 20. I'm more than a bit surprised. I thought, without special modification, that something like that would have set 20 as the value of statName, rather than the value of the variable whose name it contains. But it works! Thank you!

Post Reply

Return to “MapTool”