• Guides
  • Navigation
  • Trigger

Trigger

In this part, you will learn one of the cores of project operation — Trigger, and how to use its features and principles to make your project more interesting.

Triggers are the birthplace of all logic. You can achieve various effects through ECA (Event-Condition-Action) in Trigger. That is when some Events occur in the game and certain Conditions are met, the Actions will be triggered.

For example, for the Event "the player types 'increase money' in the chat box", when the Condition "the player’s camp is faction 1" is met, the Action "the player's gold coin increases by 100" is triggered.

NN108

Trigger Interface

Click Triggers on the Main Interface of the CliCli Editor or press the hotkey F4 to enter Triggers.

NN104

After entering Trigger Window, you can add or delete folders and triggers, and use the search function to quickly locate the trigger you want to find.

NN105

You can perform the following operations for the selected trigger: Copy, Cut, Paste, Remove, Rename, Disable, and Convert to Lua code.

NN106

After creating a trigger, you can write the ECA (Event-Condition-Action) for it in the editing area.

NN107-1

You can write commonly used variables and events in Variables and Events in advance so that the variables can be called at any time in the game, thereby reducing the memory cost and post-maintenance of the project development.

NN109

The following figure shows the window of Variables. Variables are the most commonly used data type in triggers. You can set various variable types to meet your requirements. You can learn more about how to use variables in ECA - Variable Settings.

NN110

The following figure shows the window of Events. You can set events in advance and add the required parameters of the event, then call the event in Triggers - Custom Event.

NN111

NN112

NN113

Basic Structure of Triggers

A complete trigger consists of three main parts: Event, Condition, and Action.

Event: When the content of an event is achieved, the trigger is activated and the condition and action set later start to be executed. If you set an Event as “5s after the game starts”, then 5s after the game starts, the corresponding Trigger will be activated. Each trigger can have only one event statement.

Condition: Specific condition that must be met for subsequent Action after the Event is activated. A trigger can have multiple conditions. The game logic can be executed only when all the corresponding conditions are met.

Action: Game logic that occurs after the Event is activated and the Conditions are met.

Assume the three main parts of a trigger are as follows:

Event: The lawn at the door is trimmed.

Condition: The Event is done by Tony.

Action: Gain 100 dollars. We split the entire story through the above Event-Condition-Action logic, that is to use a Trigger to run the entire story in the CliCli Editor.

There are no rigid requirements for the order of writing Event, Condition, and Action. The methods for editing the three are basically the same. However, it is recommended to write them sequentially from top to bottom, which is more consistent with the logical order. The changes in upstream content may affect the implementation of downstream content.

NN107-2

Creating and Modifying Triggers

Click the “+” behind Event/Condition/Action to create a new statement for the current part. You can also right-click the blank space and choose to create New Event, Sub-trigger, Condition, Action, and Comment.

NN107-3

NN114

If you want to change an existing Event/Condition/Action, double-click the corresponding statement and then select new content in the pop-up window to overwrite the existing content.

NN115

You may find that some parameters are not set in statements. You can view ECA - Parameter Settings to know how to set these parameters.

Adding Comments

You can add comments on each trigger statement to explain or record relevant information, so as to help multiple developers in a large project with the maintenance and iteration. Comments do not affect the running of the logic.

NN116

NN117

Object Trigger

The advantage of the Object Trigger is that it can more easily bind logic to the target object, independent of other objects, and consume fewer computing resources.

You can write the Object Trigger in Object EditorTriggers Window. The editing mode of Object Trigger is consistent with that of Triggers described previously. In Object Triggers, multiple triggers can be set for one object.

NN118

Function Library

You can convert commonly used Trigger statements into functions and store them in Function Library for reuse. After adding a statement to the Function Library, you can find the function statement in Triggers and directly use it. The operation logic of the Function Library is the same as that of Triggers. After a function is created on the left of the window, you can edit the content of the function in the Function Library on the right of the window.

NN119

Reuse of Triggers

You can export Triggers to a local PC so that you can reuse them or combine them with others. Select a trigger you want and copy it by right-clicking, then the source code of the Trigger can be pasted and saved to a local text file. You can also open another project and paste the source code into Triggers in it by right-clicking and choosing Paste.

NN120

NN120-121

NN121