-
Notifications
You must be signed in to change notification settings - Fork 4
Variables_Condition_Statements
LUTE defines variables that will live on Flow Engines. Rather than forcing designers to use code, we have defined some common variables that when used allow Nodes, Orders and Engines to share data and create more complex experiences.
Simply put, a variable is named location to store data. Variables exist on the Flow Engine and are used to keep track of progress, items, choices and more related to the player. They are often used to pass data from one order to another or be used when checking conditions.
Variables do not automatically save and restore between play but the Save Variable
mechanisms can be used to save and load variables from/to disk.
Typically when using conditional statements, we use a variable and an operation (such as equals or does not equal). This evaluation is typical when using common variable types (such as integers and strings) and will compare the provided input with the variable in question. However, certain variables (such as inventory items and locations) will use more complex evaluation methods; whilst it is not imperative to understand this at a high level, if one wishes to create new variables and custom evaluation methods then they should seek to understand this further.
Variables can be created within the Flow Engine Inspector and become visible in the Flow Engine Inspector and Window:
Each Variable needs a name which is how they are presented when used in ORders and drop-downs. You can set values of variables directly in the varibale list for most variable types. A common example might be an integer variable called 'Lives' which may initially be set to start at 3.
As we find in C#, Variables in LUTE declare the type of data they are going to contain.
Simple experiences will likely use booleans, integers and strings along with more complex types such as Locations.
Much like we would define the scope of a variable in C#, we can do the same in LUTE (currently allowing private, public
and global).
- Private is not available to other Engines which ensures that the variable is only relevant to the Engine it has been created on.
- Public indicates that the variable can be found and is intended to be used or modified by other Engines. Those other Engines will need to be able to directly access the Engine the variable is declared on to modify it.
- Global allows for sharing state among all Engines, without direct access to other Engines. It also ensures that the value of the variable can exist and outlive the Engine that it was declared by.
When looking for variables, the Engine will first look for variables on itself and then for any public variables contained on other active Engines in the scene.
A core aspect of using variables will be setting up condition statements with them. The most basic example that can be used would be an 'if statement' which uses:
- An operation (equals, greater than etc.)
- A variable (integer, float, string etc.)
To add an if statement as an order, select a Node and then add a new Order: Logic>If
. Select the new Order and observe the inspector.
The If
Order uses a list of conditions to avoid having to create unique Orders for every statement required. The first property to determine is the 'Any or All Condition' which, when using multiple condition statements, will return true if either all statements are true or any of them are true. The second property is the 'Size' which allows you to add multiple condition statements to a single Order. In this example, we are only using 1 condition statement so the first property is irrelevant.
In our example, we have chosen 'Lives' as the Variable to use in our statement. Shown by the example above, the 'Compare With' property is asking you what you want to compare the variable in question with (typically, this field reflects the type of the variable provided so in this case we can only enter integers). Finally, our 'Compare' property is asking what comparison operation we wish to use in our evaluation. In this scenario we are:
- Using 'Lives' as the variable
- Comparing this with an integer of 0
- Using 'Equals' as our operator
This will return true if the varibale 'Lives' is equal to 0 and will indicate a game over state. Orders that encapuslated within condition statements, such as If
will be indented to indicate that the condition must evaluate correctly for those orders to be executed. This can be used in tandom with Else
Orders and End
Orders to indicate the end of a condition statement check.
LUTE allows various condition orders to be used such as:
If
For
While
ElseIf
Else
End
These are typically used alongside other Orders and are useful for triggering the loading of other scenes using Scenes>LoadScene
.
Collections
in LUTE are components that live on individual GameObjects
(similar to Characters. They allow designers to taken on collections of the same of object/type in a generic way and offer lots of operations that typical C# lists offer. Their use is to allow Nodes to take actions which require arrays (or lists).
For those that have experience in programming, collections are similar to the concept of an array. Custom collections can take actions on any component that inherits from the base class of <Collection>
. You can add, remove, iterate and find items using indexes through an array of integers or floats or Nodes (or any type you wish to implement). We have a few collections available but implementing them is not too difficult. For example, Groups are a collection of Nodes.
This variable holds a reference to the Collection itself (i.e., attached to a GameObject one can see the public list and manipulate it). This allows Orders to interact with the collection and find references to certain Collections at runtime.
You need a type of collection, living on some game object, probably a new one empty one named to make its purpose clear. Then AddComponent to that object ofthe type of collection you need, such as IntCollection, or FloatCollection, etc. You can configure the starting values directly on the component.
Taking direct actions on collections is similar to any other Order in LUTE, but you will most likely want to take actions on all the items in a collection. For this you will need to iterate through them, the ForEach
Order is made especially for this purpose, however it is also easy to use a while or range based loop. These may be prefered if indicies are the driving factor your you wish to iterate over the controller in reverse.
To add Collections of a specific type, you would inherit from <GenericCollection>
. Take a look at the predefined Collections to understand this in more depth. You can override any of the generic methods in your custom Collection to support your specific needs and this can be observed in the <NodeCollection>
class.