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.
Click Triggers on the Main Interface of the CliCli Editor or press the hotkey F4 to enter Triggers.
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.
You can perform the following operations for the selected trigger: Copy, Cut, Paste, Remove, Rename, Disable, and Convert to Lua code.
After creating a trigger, you can write the ECA (Event-Condition-Action) for it in the editing area.
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.
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.
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.
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.
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.
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.
You may find that some parameters are not set in statements. You can view ECA - Parameter Settings to know how to set these parameters.
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.
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 Editor – Triggers 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.
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.
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.