Get a list of every local Lua variable.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jaramal
Posts: 6
Joined: Wed May 03, 2017 3:19 am

Get a list of every local Lua variable.

Post 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 ?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get a list of every local Lua variable.

Post 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);
} 
Post Reply