Author Topic: How to use a variable from its name  (Read 721 times)

Quick question: How do I get the filepath of an isolated document from within the document?
Something like expandFilename("~"); but there's got to be a better way than that
« Last Edit: August 10, 2012, 08:32:11 PM by Treynolds416 »

filePath( expandFileName( "./file" ) ) @ "/"

Thanks port

Thread recycled for another quick question: If I have a variable saved like %testSting = "$test"; and $test = 2; how do I use the number 2 from the variable? A test would have the console echo something like "$test is equal to 2;"

echo("$test is equal to " @ $test);

%testString is just a string that says $test

echo("$test is equal to " @ $test);

%testString is just a string that says $test
You've missed the point. I'm not an idiot, if I could use the actual variable I would

echo(eval("return " @ %testSting @ ";"));

Before you do anything like this, make sure to validate that actual variable. Anyway, are you sure there isn't another way to achieve what you're trying to do? I really don't recommend doing this.

I guess I wasn't very clear. New example:
Code: [Select]
$MyModPrefList = "$MyMod::this $MyMod::that $MyMod::these $MyMod::those";

function something()
{
    for(%i=0;%i<4;%i++)
        echo(getWord($MyModPrefList,%i) @ " = " @ unstring(getWord($MyModPrefList,%i));
}
unstring() being a completely made up function that converts a string of "$MyMod::this" to whatever $MyMod::this is equal to

Code: [Select]
%tmp = $MyModPrefList;

for ( %i = 0 ; %i < 4 ; %i++ )
{
    %tmp = setWord( %tmp, %i, eval( "return " @ getWord( %tmp, %i ) @ ";" ) );
}

// refer to %tmp

I was confused at first but I guess you meant to write getWord instead of setWord

Thanks

I was confused at first but I guess you meant to write getWord instead of setWord

Thanks

Er, what? No, I meant to write setWord.

Er, what? No, I meant to write setWord.
I see what you were doing now

I thought you were trying to just get the single word and make a new variable for it, either of these methods work for me