Planetoid Pioneers

Planetoid Pioneers

Not enough ratings
Using Targets, Triggers and Reactors
By LemonCrow
This tutorial will show you how to make use of Triggers, Target Vectors/Assemblies, and Reactors to make your blueprints and scenes interact more without getting into Activity Script editing.
   
Award
Favorite
Favorited
Unfavorite
Introduction
What Targets, Triggers, and Reactors can do:

-Give your blueprint a known point in the world.
-Have your blueprint interact with another blueprint
-Trigger doors to open and close
-Give your blueprint a "target" that it already knows, without having to scan for it.
-Give your scenes life with interactions and goals.

All of this can be done in your current scene, and not having to go through an Activity Script.
Targets
Targets are where we'll start. They are the "Link" between two objects, or between your blueprint and your target.

There are 2 meanings of Targets: Blueprint Targets and Activity Target.

Blueprint Target
Blueprint Targets are the small Connectors that show up beside your Assemblies. They are what your blueprint will either Trigger from, or be triggered by. Make sure to add all Targets here just as your starting so you don't forget! Name them something meaningful.

































Activity Targets
Under Activity Editor > Selected Blueprint you'll find 2 different types of Targets: Target Assemblies and Target Vectors.

Target Assemblies
These are Assemblies that your Blueprint knows. Assemblies will show up either when you Shift-Click on another Assembly or when you drag from one Connector to another Assemblies connector.
Uses of this are:
-Knowing another assembly without having to scan for it first.
-Triggering a door to open or close
-Sending a trigger when an AI dies
-The list goes on

Target Vectors
These will show up when you Shift-Click to a point in the world. It will be a "Local Vector" meaning the point is in relation to the blueprint.
Uses of this are:
-Giving an AI a Waypoint to walk to
-Giving an Elevator a spot to travel to
-Giving a Range for a scanner to scan
-Something a little more complicated is using a Target Vector as a variable in your code, adjusting a timers limit, or a multiplier number. Eg. self.MaxTime = vec:GetLength()
Target Naming
It's important to name your Blueprint Targets and Activity Targets something important. This will help you remember their purpose. For example:

This Blueprint has Targets with a connector for a range we specify that we look for the Pioneer, a connector to Send a Trigger to another blueprint, and a connector that we'll receive a trigger to Open the door.






Target Assemblies in which you drag from one connector to another will be automatically named. But for Shift-Clicking on another Assembly it's important to name it so you'll remember (and be able to use through code)












Lastly, Target vectors are incredibly important to name, otherwise you'll have a hard time differing them from one another. Names like Waypoint, Stops, or Aimpoint would be a good idea.

Triggers (Or Links between two Assemblies)
Now onto the fun part. Setting up a link between two Assemblies.

Linking between two Assemblies is as easy as dragging from one connector to another connector. Keep in mind the DIRECTION your dragging. It's important to make the connection from the OUTPUT to the INPUT. The output in this case is the Blue sensor block that checks if a pioneer is within range. It will send a trigger OUT from On Pio Detected IF a Pioneer is detected in range, and that trigger will go IN to Open, which has the function of opening the door.
























And here's an example of Shift + Left-Clicking to add a Target Vector. Notice how we can move around Target Vectors just by hovering over the end.
Reactors
Now we'll get into the tricky part of all of this. How we trigger from one blueprint and react with the other blueprint.

This is all done through code using these 2 simple lines:

Trigger - io.triggerLinkedToConnector(asm,connector)
Reaction - io.setReactorFunc(asm, connector, func)

Lets break it down further:
-asm is the Assembly which the connector is attached to. Almost always this will be self
-connector is the Name of the Blueprint Target Connector. Eg. "Open" or "Send Trigger"
-func this is unique in that you are calling up a function in your Blueprint:Build() that happens when a connector is triggered. NOTE: only call the function name. Eg. self.DoThis() would only be called self.DoThis as a variable.

Example of how this code is used:

We have pesky bots flying around, luckily they are all connected to a computer so with a pull of a single lever we can shutdown all of the flying bots.

Your Trigger
Blueprint:Update() if self.LeverPulled then io.triggerLinkedToConnector(self,"On") --Send a Trigger to anything connected. end end

Your Reactor (What will be triggered. In This)

Blueprint:Build() function self.TurnOff() self:SetDead(true) end io.setReactorFunc(self, "Turn Off", self.TurnOff) end Blueprint:Update() end

And our connections would look like this:

Thanks for reading!
Congrats on making it this far. Hopefully you aren't too confused. The best way to learn is by just playing around with it in the edtiors. There are a couple of colored squares blueprints that start with Trigger. Best to drag out the Proximity Trigger and hook it up to any Structure Door.

Please let me know in the comments if you're able to follow the guide or if I need to make it a little easier to understand.

-Mikey
Cheat Sheet - Use after reading through guide
Targets:
Blueprint Editor > Blueprint Targets - The small Connectors beside your blueprint. Press Delete with one highlighted to delete it.




































Assembly Editor > Target Assemblies Type 1 - Drag from Connector to connector (Output to input)
Assembly Editor > Target Assemblies Type 2 - Shift Left-Click onto another Assembly directly.
Assembly Editor > Target Vectors - Shift Left-Click onto point in world


Useful Functions

Trigger - io.triggerLinkedToConnector(asm,connector)
-- io.triggerLinkedToConnector(self,"On")
Reaction - io.setReactorFunc(asm, connector, func) --func name, don't include ()
-- io.setReactorFunc(self, "Turn Off", self.TurnOff)

self:GetTargetAssembly() -- Returns any/first Target Assembly
self:GetTargetAssemblies(rTargetName) --Returns table of Assembly Targets
self:GetTargetVectorByName(rName)
self:AddTargetVector(rVector)

Basically search the docs for Target.