In the last Chapter we discovered nodes. We learned what are action and conditional nodes where each have different properties. However we did not discover 2 useful functions that can be useful, and those are: Nested conditional nodes and exporting node scene to written Lua.
Nested Conditional nodes
Reminder: conditional nodes are nodes which act like an “If-statement” it will trigger depending on the condition.
Here, we can also nest them to create more complex events depending on what the player will do.
Consider this node scene:
we have 2 conditional nodes which control different nodes in a different scope (i.e, “key is held” is not able to trigger the health text because it can’t really see, but the “moveable health check” can!)
note: for key stuff it is recommended to select “While inside” event as it checks each game frame!
What is happening is this:
– if a player is holding forward, it will trigger the text with “You are pressing forward” with attributes like shadow, black colour etc.
– It will then go to another conditional node to check Lara’s health (note: I accidentally put “Volume activator which will check any moveable’s health :P) if it’s more than 500, it triggers the node on the left hand side, if not then it triggers the node on the right hand side.
– however if the player is not holding forward then the nodes on the left hand side each game frame and triggers the right hand side node which is “you’re not pressing forward at the moment”.
Hopefully that gives you a clear idea of nodes in general, they can become really powerful and give a huge gameplay enhancement with some creativity.
Some other useful stuff with conditional nodes
There are other things you can do with conditional nodes. In the previous example, the 2 conditional nodes are connected together, however you could have 2 unconnected conditional nodes so they work independently (in fact you can have as many conditional nodes as you can in the scene itself!)
consider this slightly modified example:
We now have split 2 conditional nodes so they work independently. This means that even if you don’t press forward, then the health check conditional node will still trigger.
note: the conditional nodes will trigger in order of appearance, so the top most conditional node will trigger and then traverse downwards to check for conditional/action nodes
Independent action nodes
Consider this again modified example:
the conditional node exists for holding the key, however you also have an action node (Which I call an “independent action node”) that is not connected to the conditional node and thus will always trigger no matter what.
Exporting node scene to written Lua
Even though you can do most of the stuff in the nodes itself, there are a few problems.
What if you would like to trigger stuff when the game starts? Or even on load?? when saving??? Or even on exit like you can with written lua???? Well thankfully you can do that.
Remember this button?
You can use it to export stuff from the scene into written lua and then paste it to your .lua file. Let’s do that!
First put the node that you would like to be exported to the scene, In this case I chose the inventory node to provide the player with a crowbar at the start:
Hit the “export lua script to clipboard” and the following message should appear:
that means the written lua behind the node has been copied and saved to your clipboard on your computer great! We can now paste it to the .lua file so enter your level .lua script and paste this to the “OnStart” function.
now this may seem complicated at first however it is not! Let’s look at each part.
“LevelFuncs.ExportedNodeFunction = function(activator)”
this basically means you are making a level function named “ExportedNodeFunction” (to indicate it was exported from node but you can rename and you shouldn’t have problems).
activator means who can activate the function?
“LevelFuncs.Engine.Node.AddInventoryItem(TEN.Objec ts.ObjID.CROWBAR_TEM, 1)”
this accesses the node that you exported and inserted into lua. in this case the crowbar will be added to your inventory on start of the game (if you did put it in the OnStart function)
Note: do not delete “TEN.Objects.ObjID.” and “LevelFuncs.Engine.Node.” this deals with a concept known as “Object Oriented programming” where the code accesses classes in order to access its functions.
Next tutorial will focus on making events to see them in practice.