The easiest way to add Lua scripting to your scene is via the Tools > Fungus > Create menu. This allows you to quickly instantiate one of the Lua prefabs that comes with FungusLua. The FungusLua prefabs all begin with 'Lua'.
The easiest way to add Lua scripting to your scene is via the Tools > %Fungus > Create menu. This allows you to quickly instantiate one of the Lua prefabs that comes with FungusLua. The FungusLua prefabs all begin with 'Lua'.
You can also access these prefabs from Fungus/Thirdparty/FungusLua/Resources/Prefabs.
You can also access these prefabs from %Fungus/Thirdparty/FungusLua/Resources/Prefabs.
@ -22,7 +22,7 @@ When you create a Lua file, add your Lua script to it in a text editor, and then
# Lua Environment Prefab
This prefab provides a @ref lua_environment "LuaEnvironment" component for executing Lua script, and the @ref lua_utils "LuaUtils" component which provides useful utilities for working with Lua, Unity and Fungus.
This prefab provides a @ref lua_environment "LuaEnvironment" component for executing Lua script, and the @ref lua_utils "LuaUtils" component which provides useful utilities for working with Lua, Unity and %Fungus.
FungusLua will automatically create a default LuaEnvironment if none exists when the scene starts, so you really only need to create a Lua Environment in your scene when you want to customize the default environment setup (e.g. Adding a string table file or registering additional c# types).
@ -10,16 +10,16 @@ You can also store the return value from the Lua script in a Flowchart variable.
# Evaluating expressions
The Fungus If command can only compare 2 variables at a time. For more complex expressions involving multiple variables or [math functions], you can use Lua to evaluate the expression and store the result in a Flowchart variable.
The %Fungus If command can only compare 2 variables at a time. For more complex expressions involving multiple variables or [math functions], you can use Lua to evaluate the expression and store the result in a Flowchart variable.
1. Add a Flowchart object (Tools > Fungus > Create > Flowchart). Add some variables to the Flowchart.
This Lua module provides handy functions for working with Lua, Unity and Fungus.
This Lua module provides handy functions for working with Lua, Unity and %Fungus.
In this page we cover some of the more generic functionality in the module, other major features are described elsewhere in the documentation.
@ -42,16 +42,16 @@ runwait(co)
# Globals vs Table mode
The Fungus module can be used in three modes, controlled by the Fungus Module option in the LuaUtils component.
The %Fungus module can be used in three modes, controlled by the %Fungus Module option in the LuaUtils component.
1. Use Global Variables: all module functions are mapped to global functions. This allows for convenient access, but it runs the risk that you might accidentally declare a variable with the same name as a Fungus module function.
2. Use Fungus Variable: all module functions are accessed through a global table called 'fungus'. This gives a degree of namespace safety at the cost of more typing.
3. No Fungus Module: the Fungus module will not be registered. Used if you don't want to use the Fungus module.
1. Use Global Variables: all module functions are mapped to global functions. This allows for convenient access, but it runs the risk that you might accidentally declare a variable with the same name as a %Fungus module function.
2. Use %Fungus Variable: all module functions are accessed through a global table called 'fungus'. This gives a degree of namespace safety at the cost of more typing.
3. No %Fungus Module: the %Fungus module will not be registered. Used if you don't want to use the %Fungus module.
Options 1 and 2 are functionaly equivalent, it's just a matter of personal preference which you want to use.
```lua
-- sub is a function in the Fungus module, mapped to a global variable
-- sub is a function in the %Fungus module, mapped to a global variable
2. Drag the Unity object you want to access to the Object field in the Object Bindings list.
3. The Key field is automatically populated based on the object name. This will be the variable name you use to access the bound object from Lua script. You can change this key to whatever string you prefer.
4. If the bound object is a GameObject, you can optionally select a component within it to bind to.
The Fungus module provides several functions for working with the standard Fungus narrative features and flowcharts.
The %Fungus module provides several functions for working with the standard %Fungus narrative features and flowcharts.
You can control Say and Menu dialogs in much the same way you use Say and Menu commands in a normal Fungus flowchart.
You can control Say and Menu dialogs in much the same way you use Say and Menu commands in a normal %Fungus flowchart.
When you use the menu() function, you supply another Lua function to call when that menu option is selected. Make sure to define the function higher up in the file before referencing it in a menu() call. If you don't explicitly set a SayDialog or MenuDialog object to use default ones are created automatically.
# Narrative example
This example Lua script demonstrates some of the Say and Menu dialog functions. To try it out, add a Lua object to the scene (Tools > Fungus > Create > Lua) and copy this script into the Lua Script text box. You may also need to add an EventSystem object in the scene (GameObject > UI > Event System) so that the menu buttons will respond to user input.
This example Lua script demonstrates some of the Say and Menu dialog functions. To try it out, add a Lua object to the scene (Tools > %Fungus > Create > Lua) and copy this script into the Lua Script text box. You may also need to add an EventSystem object in the scene (GameObject > UI > Event System) so that the menu buttons will respond to user input.
1. Add as SayDialog to the scene (Tools > Fungus > Create > SayDialog)
1. Add as SayDialog to the scene (Tools > %Fungus > Create > SayDialog)
2. Select the Lua object in the hierarchy and find the LuaBindings component.
3. Add a binding to the SayDialog game object, and select the SayDialog component. N.B. Make sure to select the correct component!
4. In Lua script, you can now activate this SayDialog using the setsaydialog() function, by passing the key of the SayDialog binding.
@ -220,11 +220,11 @@ See the docs for the @ref conversation "Conversation System".
# Flowchart functions
We've added special functions for say() and menu() because these are so common in Fungus games. To execute any other commands in Fungus from Lua, you must do it in conjunction with a Flowchart & Block, like this:
We've added special functions for say() and menu() because these are so common in %Fungus games. To execute any other commands in %Fungus from Lua, you must do it in conjunction with a Flowchart & Block, like this:
1. Add a Flowchart and a Block (e.g. "MyBlock") in the scene.
2. Add the Fungus commands you want to execute from Lua in the Block. (e.g Play Sound)
3. Add a Lua object to the scene (Tools > Fungus > Create > Lua)
2. Add the %Fungus commands you want to execute from Lua in the Block. (e.g Play Sound)
3. Add a Lua object to the scene (Tools > %Fungus > Create > Lua)
4. In the LuaBindings component, add a binding to the Flowchart gameobject, and select the Flowchart component.
5. In the LuaScript component, use the runblock() function to execute the Block, passing the bound flowchart and name of the block as parameters.
The LuaEnvironment component manages all the variables, functions, executing code, etc. for a single Lua context, and provides handy functions for loading and running Lua scripts. In order to run Lua code there must be at least one LuaEnvironment component present in the scene.
You can create one via (Tools > Fungus > Create > LuaEnvironment). You usually don't need to explicitly create a LuaEnvironment though because FungusLua will create one automatically when there isn't one in the scene at startup.
You can create one via (Tools > %Fungus > Create > LuaEnvironment). You usually don't need to explicitly create a LuaEnvironment though because FungusLua will create one automatically when there isn't one in the scene at startup.
![LuaEnvironment](fungus_lua/lua_environment.png)
@ -16,5 +16,5 @@ The 'Remote Debugger' option activates the built-in MoonSharp remote debugger to
# LuaUtils
When you create a LuaEnvironment object via (Tools > Fungus > Create > LuaEnvironment), the created gameobject has another component called LuaUtils which adds many useful features to the basic LuaEnvironment setup. See the @ref lua_utils "Lua Utils" section for more info.
When you create a LuaEnvironment object via (Tools > %Fungus > Create > LuaEnvironment), the created gameobject has another component called LuaUtils which adds many useful features to the basic LuaEnvironment setup. See the @ref lua_utils "Lua Utils" section for more info.
This Lua module provides handy functions for working with Lua, Unity and Fungus.
This Lua module provides handy functions for working with Lua, Unity and %Fungus.
In this page we cover some of the more generic functionality in the module, other major features are described elsewhere in the documentation.
@ -42,11 +42,11 @@ runwait(co)
# Globals vs Table mode
The Fungus module can be used in three modes, controlled by the Fungus Module option in the LuaUtils component.
The %Fungus module can be used in three modes, controlled by the %Fungus Module option in the LuaUtils component.
1. Use Global Variables: all module functions are mapped to global functions. This allows for convenient access, but it runs the risk that you might accidentally declare a variable with the same name as a Fungus module function.
2. Use Fungus Variable: all module functions are accessed through a global table called 'fungus'. This gives a degree of namespace safety at the cost of more typing.
3. No Fungus Module: the Fungus module will not be registered. Used if you don't want to use the Fungus module.
1. Use Global Variables: all module functions are mapped to global functions. This allows for convenient access, but it runs the risk that you might accidentally declare a variable with the same name as a %Fungus module function.
2. Use %Fungus Variable: all module functions are accessed through a global table called 'fungus'. This gives a degree of namespace safety at the cost of more typing.
3. No %Fungus Module: the %Fungus module will not be registered. Used if you don't want to use the %Fungus module.
Options 1 and 2 are functionaly equivalent, it's just a matter of personal preference which you want to use.
FungusLua is a simple way to embed Lua scripting into your Unity project. Lua is an easy to learn scripting language so it's a great way to empower artists, writers and designers to use more of the power of Unity.
At its core, FungusLua allows you to control any Unity object from Lua script. It has useful utilities for using Fungus flowcharts and dialogs, persisting variables between scene loads, localization, and working with the Unity Test Tools.
At its core, FungusLua allows you to control any Unity object from Lua script. It has useful utilities for using %Fungus flowcharts and dialogs, persisting variables between scene loads, localization, and working with the Unity Test Tools.
We made FungusLua in response to requests from the Fungus community for a way to script Fungus commands from a text file or spreadsheet. We figured that if people are going to be writing commands in text files, why not go all the way and add a powerful embedded scripting language?
We made FungusLua in response to requests from the %Fungus community for a way to script %Fungus commands from a text file or spreadsheet. We figured that if people are going to be writing commands in text files, why not go all the way and add a powerful embedded scripting language?
FungusLua comes as part of the [Fungus asset] available on the Unity Asset Store.
FungusLua comes as part of the [%Fungus asset] available on the Unity Asset Store.
# Tutorial Video
@ -20,12 +20,12 @@ This video shows how to use many of the features available in FungusLua. It's mo
# Using FungusLua On Its Own
FungusLua can easily be used on its own if you don't need the rest of the functionality in Fungus.
FungusLua can easily be used on its own if you don't need the rest of the functionality in %Fungus.
1. In the project window, move the Fungus/Thirdparty/FungusLua folder up to the root of the project.
2. Delete the Fungus and FungusExamples folders.
1. In the project window, move the %Fungus/Thirdparty/FungusLua folder up to the root of the project.
2. Delete the %Fungus and FungusExamples folders.
The Tools > Fungus menu will now only show options for creating FungusLua objects. Obviously you won't be able to use Fungus functions like say(), menu(), etc. anymore, but you can still use LuaEnvironment, LuaBindings, LuaScript to add Lua scripting to your game.
The Tools > %Fungus menu will now only show options for creating FungusLua objects. Obviously you won't be able to use %Fungus functions like say(), menu(), etc. anymore, but you can still use LuaEnvironment, LuaBindings, LuaScript to add Lua scripting to your game.
# About Lua
@ -44,7 +44,7 @@ FungusLua is essentially a set of wrapper components built on top of MoonSharp w
The [MoonSharp tutorials] and [MoonSharp forum] are great resources to learn how MoonSharp works, especially for more advanced usage.
[Lua]: http://www.lua.org/about.html
[Fungus asset]: http://u3d.as/f0T
[%Fungus asset]: http://u3d.as/f0T
[Programming in Lua]: http://www.lua.org/pil/1.html
The LuaScript component provides an easy way to run Lua scripts in your scene. You can create a LuaScript object via (Tools > Fungus > Create > LuaScript).
The LuaScript component provides an easy way to run Lua scripts in your scene. You can create a LuaScript object via (Tools > %Fungus > Create > LuaScript).
The LuaUtils component provides support for simple text localisation.
1. Define your language strings in a JSON file and save it in the project assets folder.
2. Add a LuaEnvironment component to your scene - e.g. Tools > Fungus > Create > LuaEnvironment
2. Add a LuaEnvironment component to your scene - e.g. Tools > %Fungus > Create > LuaEnvironment
3. In the LuaUtils component, set the String Table property to reference your JSON file asset.
4. Use the {$VarName} syntax to subsitute a localised string anywhere that string substitution is supported. e.g. in a Lua script:
@ -24,7 +24,7 @@ You can use the {$VarName} syntax anywhere that variable subsitution is supporte
- Save Variable command - save key
- Delete Save Key command
You can also extend the Fungus string substitution system with your own components. Implement the StringSubstituter.ISubstitutionHandler interface in a Monobehavior subclass and then return the modified string from SubstituteStrings().
You can also extend the %Fungus string substitution system with your own components. Implement the StringSubstituter.ISubstitutionHandler interface in a Monobehavior subclass and then return the modified string from SubstituteStrings().