Endless Events

This article assumes you understand the basics of the editor including saving/loading, navigation, and inspecting objects. If not, then start here Editor Basics

What is an event?
Think of an event as a “'''When... Then…'''”

In other words, an event will trigger WHEN a code defined set of conditions occurs, THEN tell an unrelated object to do something.

In the Endless Mission you can do this WITHOUT writing any code!



What can I do with events?
Theoretically, anything!

At least anything the author of the script you’re calling to setup to be able to be called from events via “EndlessEventVisible,” which is detailed in the scripting section below.

Don't worry though, we provide a lot of built in events that you can use without scripting! We'll cover an example next

Event Tutorial
In this brief tutorial, we are going to use events to setup a door that opens after you have killed 5 enemies.

In game, go to the content portal and download the UGC game titled “Event Tutorial”

(https://portal.theendlessmission.com/content/item/237e54b7-de15-46ca-808a-d4662bc21423)

After opening it navigate to the folder title "Tutorial Items" and select the "Health Depleted Smart Condition" This is a condition that does SOMETHING once X things are killed. In this case, it is set up to call an event after 5 weasels are killed.



Notice the "OnConditionMet" part of the inspector. This is an event, and it is the event we'll be focusing on for this tutorial.

Press the "+" to add a new function call to the event. It will then look like this:

Drag the "Platformer Smart Door" from the Hierarchy into the top slot.

What you're doing here is setting which object you want to give the command to. Your "Target"

Then use the drop down to select the "Openable/Open" function. This the the command



The final result should look like this



In this case the bool argument is just telling the door to open Forwards (true) or Backwards (false). Either is fine for this tutorial.

Now play the level and test out your changes.

When you kill the 5 weasels, the condition will complete.

When the condition completes, it fires the "OnConditionMet" event, which if you've setup everything correctly, will open the door and allow you to collect the pineapple finishing the game!

When... the condition is met Then… open the door

Other event examples
There are many other built in events that can easily create a LOT of quick and easy gameplay. Here are just a handful of objects with events you can hook into, or objects that have functions that can be hooked up to these events.
 * Smart Objects
 * Smart Conditions
 * Anything with a Health Controller
 * Collectables
 * Smart UI
 * Turning an object on or off
 * Turning a script on or off

By combining these, there is a LOT of gameplay you can create, without any code! Check out "The Polybius Protocol" to see an impressive example game that is built off of events, with ZERO custom code!

https://portal.theendlessmission.com/content/item/c0f834b3-b5d5-41eb-bc14-fc64a875937f

Scripting: What types of events can exist?
An EVENT BROADCASTER can broadcast any amount of information, and an EVENT RECEIVER, that is the thing you hook up to the event, can have either, a single primitive type (float, int, bool, string) or a set of values that MATCH the event signature of the EVENT BROADCASTER.



Scripting: How do I expose my functions to events?
Above your function definition add “[EndlessEventVisible]” This is a method attribute, aka a piece of data describing some metadata about a function - in this case that we allow the Inspector to see the function in an event drop down like above.

Scripting: How do I create my own events?
This line defines what the event is called"[SerializeField] EndlessEvent OnMyThingHappened= new EndlessEvent;"This line fires off the event!"OnMyThingHappened.Invoke;"If you want a custom set of parameters on your event, you’ll have to first define the type of event first like this first:"[System.Serializable] public class HealthValueEvent : EndlessEvent { }"Then you’d define the actual event like this, using your new type."[SerializeField] HealthValueEvent OnNewHealthValue = new HealthValueEvent;"Finally you’d call it like this, passing in a matching set of parameters to what you defined above!"OnNewHealthValue.Invoke(5.0f);"