No, GetVariable merely returns a value, it doesn't return a reference, or anything fancy like that.
You could use a hash, to keep track of the perl variables and their corresponding MC variables, like this:
sub testsub
{
my %variables = ('a' => 'test1','b' => 'test2', 'c' => 'test3');
my ($a, $b, $c); #make local variables (my ${$id}) wont work)
foreach $id (keys %variables)
{
${$id} = $world->GetVariable($variables{$id});
}
if ($a == 1)
{
$world->SetVariable($variables{'a'},0);
}
if ($b == 2)
{
$world->SetVariable($variables{'b'},0);
}
if ($c == 3)
{
$world->SetVariable($variables{'c'},0);
}
}
I suppose you COULD use tie and things like that to link local variables to mushclient variables, but that seems like an awful lot of overhead.
But once you would have it set up, the local variables and the mushclient variables would be linked for getting and setting.
I don't think you'll be doing enough variable name changing to make either of these things worthwhile, well, maybe at the beginning while you’re getting comfortable with scripting, but once you've gotten the hang of it, all it would do is slow down your scripts. Especially since you won't need to change the variable names at all once you’re more comfortable and your scripts are more mature.
Heck, variables can all be changed with a simple find replace in the world file. Which wouldn't be too much of a hassle for the coder, and would incur no penalty for the user.
|