Does Dialogue System Have Support For Loading .lua files?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Soulessvagabond
Posts: 2
Joined: Wed Mar 10, 2021 8:07 am

Does Dialogue System Have Support For Loading .lua files?

Post by Soulessvagabond »

So I know that LUA is used for Dialogue System for Unity to handle conditions, variables and general control of the database at runtime. What I was wondering is does Dialogue System For Unity have an inbuilt ability to load/parse .lua files if I were to say set up lua functions within a file rather than linking C# methods through the tutorial listed in the docs?
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Does Dialogue System Have Support For Loading .lua files?

Post by Tony Li »

Hi,

There are two ways to do that.

You can put your Lua code in the Global User Script section of your dialogue database, which you can edit on the Database page of the Dialogue Editor window.

Or you can load the .lua file into a string and send it to Lua.Run():

Code: Select all

string luaCode = System.IO.File.ReadAllText("myfile.lua");
Lua.Run(luaCode);
The Dialogue System's Lua environment is sandboxed for safety, so it doesn't give direct access to the OS, including files. However, you can read files in your own C# scripts like the code above and then run that in Lua.
Soulessvagabond
Posts: 2
Joined: Wed Mar 10, 2021 8:07 am

Re: Does Dialogue System Have Support For Loading .lua files?

Post by Soulessvagabond »

Ah very interesting! Thanks!
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Does Dialogue System Have Support For Loading .lua files?

Post by Tony Li »

Glad to help!
Post Reply