This article introduces how to edit Block Scripts.
Interface Description
- Canvas, the main editing area
- The file currently being edited
- Element classification, click any element to expand the element selection interface
- Properties panel
Element classification description
-
The graphic element categories corresponding to the regions are:
-
Search: Enter keywords to search for graphics.
-
Commonly used: The graphics set as commonly used graphics will be here.
-
Event: It will be triggered when the conditions are met, which is the beginning of logic.
-
Conditions: used for script flow control.
-
Behavior: actual operation on entities\data.
-
Modules: Some module-specific behaviors.
-
Data: Processing of data.
-
Variables: Use existing variables or add variables.
-
Function: Use or create a custom function.
-
External call: call custom functions of other scripts.
Use of graphics
Block Description
The bulge under the primitive indicates that other primitives can be linked to it.
The depression above the primitive means that other primitives can be linked before this primitive, and it will only run after the preceding primitives run.
If there is no depression on the top but a bulge on the bottom, it means that the primitive is the starting point of a logic segment, usually an event primitive.
If there is no convexity or concaveness above or below, it means that the primitive is a piece of data and can be applied to other primitives.
The primitives will have input and output parameters:
Input parameters:
The input parameter is blank by default, and the type marked inside it is the type of the required parameter.
The script name in this element is also a required parameter, but using the resource selector, you can directly select the corresponding resource in the project without considering type matching.
Output parameters:
The output parameters are colored squares by default, which can be dragged to fill in the required input parameter boxes:
Use of primitives
After selecting the element you want to use in the category, click or drag it to the canvas to use the corresponding element.
Using the primitive with the groove on top, you can join the two primitives together:
The logic of a group of primitives is always from top to bottom:
For a group of graphics elements connected in series, the necessary input parameters need to be filled with appropriate data to ensure the normal operation of the script. Inappropriate variables will result in an error. Click the error to see the error message:
When you drag an element, the elements below it will be dragged away as well:
Hold down the Ctrl key and drag to only drag the current element, and the elements below will automatically connect to the ones above:
Element Properties Panel
Click on the element and it will be selected.
In the Inspector panel on the right, you can view detailed information of the selected element, including its name, description, parameter name, parameter type, return value type, return value description, etc.
Flow Control
The default execution order of Block Scripts is from top to bottom. You may often need code flow control to implement complex logic.
Please refer to the following link for detailed instructions:
Variables
Three types of variables can be defined or modified at the variable location:
- Global entity attributes: global component attributes, support customization. You can obtain or modify customized global entity attributes in any script.
- Script variables: variables used only in the current script, other scripts can obtain and modify them externally.
- Local variables: variables that are only used in the current code block and are invalid outside the code block.
Global entity properties
Global entity properties can be added via the entity component properties in the component settings.
After creating the global entity attribute, you can use Get Global Entity to obtain the attribute:
Use the Set Global Entity to set this property:
Script variables
In the Variables category, there is a Create Variable button:
The variables created in this way are script variables and are used for data processing in the current script.
In other scripts, you can get and set this variable through external references:
Please note when referencing other scripts externally: when getting and setting, you need to specify the corresponding entity mounted by the referenced script.
Local variables
The local variable primitive allows you to create variables that are only available in the current code block:
You can rename a variable by double-clicking the variable name:
A code block is a continuous sequence of primitives. It is worth noting that the “if-else” primitive in the conditional classification is two code blocks by default. Each “if”, “else”, and “else-if” is an independent code block.
Custom functions
Both functions with and without return values are supported in Block Scripts.
A function with a return value cannot be linked to other entities when called. The calling entity is the return value.
Functions without return values can be linked to other primitives when called.
Wait: When the primitive is an asynchronous function, it will be blocked and the next primitive will be executed after the asynchronous function is executed.
Execution: If the primitive is an asynchronous function, it will not be blocked and the following primitive will continue to be executed.
An asynchronous function is a function that uses primitives that perform asynchronous processing, such as “wait”.
Note: Using asynchronous primitives in functions with return values is not supported.
If you need an asynchronous function to return a value, use a void function and use an output variable.
Regardless of whether a custom function has a return value or not, you can use the function’s output variable below the calling primitive to obtain the output.
Custom Events
In addition to the various events officially provided, you can also trigger logic through custom events.
Click the button to perform custom event management:

Right-click in the custom events list to manage custom events:
Click the + button to create a new custom event:
Here you need to set the name of the custom event, the object type to which the custom event signal is sent, and the parameters. Only the specified object type can receive the signal that triggers the event.
Send a custom event to all players at the start of their turn
The player triggers the logic after receiving the custom event signal
Search and common use of graphics elements
Enter keywords to search for corresponding elements
In the element selection interface, right-click an element to set it as a frequently used element, and then you can quickly use the element in the frequently used element category.
Example
Let’s use a simple example to demonstrate the use of the script:
The design is as follows:
- Each player will be given an M4A1 when joining the game.
- When a player fires, 1 health point will be deducted from his own health each time he fires.
Create Script:
- The requirement is global, 2. is for each player. So you need to mount a script globally and for each player. The server needs to know about the distribution of props and the deduction of life, so both are created as server scripts.
Edit Script:
For 1, each player who joins the game needs to issue props once:
For adding props primitives, three parameters are required: the target for adding props, the props to be added, and the number of props to be added.
The target of adding props is the player who triggered the event when the player joins the game. The prop is selected as M4A1 through the resource manager, and the quantity is 1.
For 2, a health deduction needs to be performed every time a shot is fired:
We find that the primitives do not actually have their health deducted:
Filling in negative numbers in the health recovery primitive’s parameters will not deduct health
However, as a player attribute, health can be adjusted by setting properties:
To set the attribute primitive, you need the entity to be set, the attribute and value to be set, and several parameters to be calculated.
The entity whose attributes are set is the current player, so you can use this entity and double-click the parameter position to quickly fill in this entity.
The attribute value that needs to be changed is the current health value, select the current health value.
The set value is the current health value minus 1, so the current health needs to be obtained.
Use the subtraction method in data classification to reduce it by one and add parameters:
You can also use the operation of setting attribute primitives directly to implement this logic:
Run the debugger to view the results:
Everyone was issued an M4A1.
Fired 8 times and lost 8 health points.
When firing, it is triggered every time a firing command is executed. The shooting of a burst weapon before the weapon is lowered is considered as one firing, and this event can only be triggered once.