Node Copied to Clipboard!

Advanced Templates

Sometimes you will encounter a node sequence that contains a lot of reusable pieces but right in the middle of the would be template is an action, such as a series of animations, that is often changed depending on the arguments. To encapsulate this variable action sequence in a template we can expose it so that we can define the variable action sequence when calling the template.

Return a value

Sometimes you may want to use a template to calculate a value. If you want to use this value outside of the template you will have to return it from the template. For example if we make a template that takes in a list of floats and adds them all up we would probably want to return the result from the template so we could use it in our lesson.

  • Inside the extracted template click on the begin node and from the properties panel graph the return property to the node by pressing the 'X' next to it.

  • Input the type of the value you will be returning into the return parameter. For this example we will return a float(type).

  • At the end of the template right-click on the storyboarder and call the return node. Graph the parameter property from the properties tab by pressing the 'X' next to it and drag in the return value.

  • The return value will become the output of the template and it comes out of the bottom handle. We can then save the output to a variable to use later or feed the value right into another function. For this example we feed the output into a console.Log node to print the result to the console tab.

Exposing Actions

In this example I want to make a template that highlights a component, waits for user to click the part, animates it and then unhighlights it. Since many of the parts would require their own animation sequences, for example, bolts use rotation and move on the X axis where another part I only want to move it on the Y axis I will need to expose the animate sequence as a variable Action.

  • Extract the template like you normally would if the animations would remain the same for all parts. Inside the template press the plus button on the begin node to add a new parameter.

  • Right-click on the storyboarder and add an "Action" type, dereference a variable from it and give it a descriptive name. It will be important to differentiate it from the other parameters as an Action so it is recommended to add "Action" at the end of the variable name. Since I am creating an animation sequence I will name the variable "AnimateAction" for this example.

  • Add this parameter to the begin node. After compiling the lesson, you can then right-click on the storyboarder and call the new Action Variable.

  • Delete the animate nodes you have in the template and replace each group of them with a single instance of the action variable.

  • Go to the main storyboarder and update the parameters on your template. You can now add any sequence of nodes to the right of the Action variable parameter you created. This sequence will be played once the line of execution reaches the action variable within the template, then it will continue.