Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Posts
    16

    Get the name of a variable?

    Is it possible to get the name of a variable?
    For example:

    Code:
    myvar="Fluffy";
    Debug.Print(myvar.."\r\n");
    Debug.Print(GetVarName(myvar.."\r\n"));
    would result in:

    Code:
    Fluffy
    myvar

  2. #2
    Join Date
    Mar 2006
    Posts
    61
    Quote Originally Posted by thisisauniqueusername View Post
    Is it possible to get the name of a variable?
    For example:

    Code:
    myvar="Fluffy";
    Debug.Print(myvar.."\r\n");
    Debug.Print(GetVarName(myvar.."\r\n"));
    would result in:

    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?

  3. #3
    Join Date
    May 2006
    Posts
    16
    For Debugging purposes I use this Script:

    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
    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.

    Code:
    mytable={}
    for x=1,5 do
    	mytable[x]=x;
    end
    Debug.TablePrint(mytable)
    results in
    Code:
    [1](number)::1
    [2](number)::2
    [3](number)::3
    [4](number)::4
    [5](number)::5
    I would prefer it to be
    Code:
    [mytable]
    	[1](number)::1
    	[2](number)::2
    	[3](number)::3
    	[4](number)::4
    	[5](number)::5

  4. #4
    Join Date
    May 2006
    Posts
    16
    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"

  5. #5
    Join Date
    Apr 2007
    Posts
    165
    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.

  6. #6
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    Quote Originally Posted by Teqskater View Post
    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.
    Nee is inderdaad nog al lastig, maarja:P

    **No it's quite difficult indeed, ah well:P**
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

Similar Threads

  1. Variable in a variable name??
    By GurkGager in forum Setup Factory 6.0
    Replies: 1
    Last Post: 05-18-2004, 02:31 PM
  2. Can't copy files with variable??
    By SonG0han in forum AutoPlay Media Studio 5.0
    Replies: 1
    Last Post: 03-06-2004, 03:58 AM
  3. Replies: 1
    Last Post: 11-21-2001, 01:10 PM
  4. Registry Variable Failure
    By ggallo in forum Setup Factory 5.0
    Replies: 3
    Last Post: 08-30-2001, 01:51 PM
  5. Validation of custom variable references?
    By John Schacher in forum Setup Factory 5.0
    Replies: 1
    Last Post: 07-18-2000, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts