Click or drag to resize

Event Handlers

Scripting Basic KnowledgeManual / Advanced / Event HandlersType and Metadata Programming

Event Handlers

This article will describe how to create event handlers.

Contents
Overview

You can create an event handler via any of the three basic scripting methods: in C# file, using C# script and using Flow Graph.

In the examples below, a code will be created that is called when the scene is initialized. To do this, select the scene object, in Settings Window go to the Events tab. Next, click on the add handler button. In this case, we need an Enabled Event (scene enable event).

Screenshot999999520 2.png
Add handler to C# script

For those who are familiar with programming, the easiest way is to use C# scripts.

After clicking on the add button, a context menu will appear with a choice of what type of object to create.

Screenshot999999521.png

When you select a C# script, a C# Script object is created. It adds the handler code.

To test, you can add the code Log.Warning("Test");

Screenshot999999522.png

After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.

Screenshot999999523.png
Add handler to C# file

To add handlers in a regular C# file, the resource must have a basic C# class. To create a base class, when creating a resource, you need to enable the Create C# class checkbox.

After creation, a message appears stating the need to restart the editor. This is necessary in 
order to connect the C# class that is used by the scene. C# file will be compiled upon reboot.
Screenshot999999525 2.png

After creating the resource, two files will appear, one of which will be a regular C# file.

Screenshot999999526 2.png

Now you can create a handler.

Screenshot999999527.png

And add Log.Warning("Test");

Screenshot999999528.png

After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.

Screenshot999999523.png
Add handler to Flow Graph

This section describes how to create a handler using the Flow Graph visual scripting tools.

First you need to add a handler in the same way it was added in the previous examples.

Screenshot999999529.png

The Flow Graph Editor will open. It will have one Event Handler node.

Screenshot999999530.png

Next, attach another node to it with a call to the Log.Warning method. To do this, in Resources Window, find the Log.Warning method and drop it into the workspace. The method is in All types\NeoAxis\Log.

Screenshot999999531 2.png

Now you can adjust the properties of the new node. Enable the Flow Support property in order to be able to connect the node with others. Fill in the Message parameter.

Screenshot999999534 2.png

Next, connect the first node's Handler Flow output to the second's node Entry input.

Screenshot999999536 2.png

After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.

Screenshot999999523.png
See also
Scripting Basic KnowledgeType and Metadata Programming