Is it possible to get the name of a variable?
For example:
would result in:Code:myvar="Fluffy"; Debug.Print(myvar.."\r\n"); Debug.Print(GetVarName(myvar.."\r\n"));
Code:Fluffy myvar
Professional Software Development Tools
Is it possible to get the name of a variable?
For example:
would result in:Code:myvar="Fluffy"; Debug.Print(myvar.."\r\n"); Debug.Print(GetVarName(myvar.."\r\n"));
Code: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?
For Debugging purposes I use this Script:
It prints out the table structure and values of whatever table I pass it.Code: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
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.
results inCode:mytable={} for x=1,5 do mytable[x]=x; end Debug.TablePrint(mytable)
I would prefer it to beCode:[1](number)::1 [2](number)::2 [3](number)::3 [4](number)::4 [5](number)::5
Code:[mytable] [1](number)::1 [2](number)::2 [3](number)::3 [4](number)::4 [5](number)::5
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"
This is realy a classic problem when you advance to a higher level of programming in AMS. I had the problem once too.. I like to see that i wasnt the only one.
![]()