PDA

View Full Version : Get the name of a variable?


thisisauniqueusername
10-26-2008, 04:51 PM
Is it possible to get the name of a variable?
For example:

myvar="Fluffy";
Debug.Print(myvar.."\r\n");
Debug.Print(GetVarName(myvar.."\r\n"));

would result in:

Fluffy
myvar

Bags
10-26-2008, 08:42 PM
Is it possible to get the name of a variable?
For example:

myvar="Fluffy";
Debug.Print(myvar.."\r\n");
Debug.Print(GetVarName(myvar.."\r\n"));

would result in:

Fluffy
myvar

This seem rather useless because you already know the name of the variable when you passed it to GetVarName(). You see what I am saying?

If you wanted to get a variable name from source while the executable is running in AMS you could create a function that gathers the objects source scripts via Page.GetObjectScript and parse it out for variable names.

Perhaps if you explain a little more on what exactly it is you are trying to accomplish we could better help you out here?

thisisauniqueusername
10-27-2008, 12:31 AM
For Debugging purposes I use this Script:

function Debug.TablePrint(tbl,indent)
Debug.ShowWindow(true)
local boolDebugMode=Debug.GetTraceMode();
local index='';
local value='';
Debug.SetTraceMode(false)
if (tbl~=nil) then
if (indent==nil) then
indent=""
else
indent=indent.." ";
end
if (type(tbl)=="table") then
for index,value in tbl do
if (type(value)=="string" or type(value)=="number") then
Debug.Print(indent.."["..index.."] ("..type(value)..")::"..value.."\r\n")
elseif (type(value)=="boolean") then
if (value==true) then
Debug.Print(indent.."["..index.."] ("..type(value)..")::"..'true'.."\r\n")
else
Debug.Print(indent.."["..index.."] ("..type(value)..")::"..'false'.."\r\n")
end
elseif (type(value)=="table") then -- ommit this to have (table) printed next to the tables
Debug.Print(indent.."["..index.."]\r\n") -- ommit this to have (table) printed next to the tables
else
Debug.Print(indent.."["..index.."] ("..type(value)..")\r\n")
end
Debug.TablePrint(tbl[index],indent)
end
end
end
Debug.SetTraceMode(boolDebugMode)
end

It prints out the table structure and values of whatever table I pass it.
The first line that is printed out in it, is the First Index of the table. I would like the first line that it prints out, to instead be the name of the table itself, and then the indexes and values.

mytable={}
for x=1,5 do
mytable[x]=x;
end
Debug.TablePrint(mytable)

results in
[1](number)::1
[2](number)::2
[3](number)::3
[4](number)::4
[5](number)::5

I would prefer it to be
[mytable]
[1](number)::1
[2](number)::2
[3](number)::3
[4](number)::4
[5](number)::5

thisisauniqueusername
10-27-2008, 12:47 AM
nevermind - realized that even if i could print out the name of the variable, it still would not give the result I was looking for, as the variable name inside the function would be "tbl" instead of "mytable"

Teqskater
10-27-2008, 06:09 AM
This is realy a classic problem when you advance to a higher level of programming in AMS. I had the problem once too. :lol. I like to see that i wasnt the only one. :lol

Imagine Programming
10-27-2008, 10:58 AM
This is realy a classic problem when you advance to a higher level of programming in AMS. I had the problem once too. :lol. I like to see that i wasnt the only one. :lol

Nee is inderdaad nog al lastig, maarja:P

**No it's quite difficult indeed, ah well:P**