Reload lua environment?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
patchfoot
Posts: 6
Joined: Thu Sep 18, 2014 12:02 pm

Reload lua environment?

Post by patchfoot »

For debugging purposes it would be nice to have a quick way to just toss out any changes to the Dialogue System LUA environment since loading without restarting the build. Also to sort of hot reload changes made to the files it imports I guess. Is there a simple way to do that?
User avatar
Tony Li
Posts: 21049
Joined: Thu Jul 18, 2013 1:27 pm

Reload lua environment?

Post by Tony Li »

Hi,



Yes, call DialogueManager.ResetDatabase(). It takes one parameter, which can be:



RevertToDefault: Restores the default database, removing any other databases that were added after startup, or

KeepAllLoaded: Keeps all loaded databases in memory, but reverts them to their starting values.



There are also equivalent Reset Database actions for visual scripting environments such as PlayMaker and plyGame.



You can also manually edit the Lua environment by adding a Lua Console to your scene. In my test scenes, I usually add this as a matter of course so it's available if I need it.
patchfoot
Posts: 6
Joined: Thu Sep 18, 2014 12:02 pm

Reload lua environment?

Post by patchfoot »

If I've added my own tables to the Lua environment (not through Dialogue System) does this toss those out as well?
User avatar
Tony Li
Posts: 21049
Joined: Thu Jul 18, 2013 1:27 pm

Reload lua environment?

Post by Tony Li »

No, it doesn't toss those out. It only resets the Dialogue System tables:



Actor[]

Item[]

Location[]

Conversation[]

Variable[]



It also doesn't include your own tables or variables in saved games. But you can hook into PersistentDataManager to add your own data to saved games. Just assign a method to the PersistentDataManager.GetCustomSaveData delegate. It should return Lua code. For example, say you want to save a Lua variable highScore that's not in the Variable[] table. You can do this:

PersistentDataManager.GetCustomSaveData = GetMySaveData;



string GetMySaveData() {

return "highScore=" + Lua.Run("return highScore").AsInt + ";";

}

This will return a string that looks something like:

highScore=42;

This will get added to the saved game string. When the Dialogue System restores a saved game, it simply runs the Lua code in the saved game string.



You can get even fancier by registering C# functions with Lua and adding calls to them in your GetCustomSaveData method. This allows you to run C# functions when loading a game.



API: PersistentDataManager


Post Reply