Page 1 of 1

Get a list of every local Lua variable.

Posted: Tue May 09, 2017 11:46 am
by Jaramal
Hello,

I wondered if there is a way to get the list of every lua variable from script. I mean : those declared in the current Database, and those declared on runtime ?
As far as I know, there is a lua array called Variable[], and we can use the function DialogueLua.GetVariable() from script, but only by using the name of the variable.
What would be the correct way to do it ?

Re: Get a list of every local Lua variable.

Posted: Tue May 09, 2017 12:19 pm
by Tony Li
Hi,

Lua can return a table (array) as a return value. The AsTable property returns it as a LuaTableWrapper, so you can do this:

Code: Select all

var variableTable = Lua.Run("return Variable").AsTable;
foreach (var variableName in variableTable.Keys) {
    Debug.Log(variableName);
}