Cẩm nang người chơi

Scripts


Scripts are used to control the game’s progress by manipulating specific objects under the right conditions, and thus realizing logic that is not possible or difficult to achieve by relying on self-contained objects.

Distinction between script types

Block and code scripts

We provide two ways to edit scripts: block scripts and code.

image-20240718182931412

Block scripts are more intuitive and easy to use with visual blocks for script editing. But the complexity rises faster and the script is more difficult to maintain when writing complex logic.

image-20240718183124409

Code Scripting Script editing using code is more free and maintainable when dealing with complex logic.

Server and Client Scripts

Regardless of block or code, scripts need to differentiate between running platforms: server or client.
Server scripts can only use events and interfaces supported by the server, and the same applies to clients.

image-20240718183255210

Events that can only be run under the server platform

Static Scripts

Scripts are all supported to be configured as static scripts:

image-20240719152909186

Static scripts will always run under the global module.

image-20240719153023952

Static scripts can also be mounted under other entities at the same time, but be careful not to conflict with its own logic on the global entity.

image-20240722180436604

With the static script New ECA.eca mounted on the global entity, the internal event is triggered twice. (This configuration is not recommended.)

image-20240722180506048

image-20240722180749960

Configure New ECA.eca on both Global and Player, and the internal event will be triggered once on the Global and Player entities, respectively, if the logic supports it.

Create a script

Right click in the editable assets area to create a new script

image-20240719143643018

image-20240719143706370

Select New when mounting the script:

image-20240719144041369

image-20240719144112007

image-20240719144219525

image-20240719144236787

image-20240719144248170

New scripts created in this way will be automatically mounted on the corresponding entity and will be automatically named with the name of the current entity.

When creating a script, you need to select/configure the category of the script:

  1. server script or client script, which affects the events and interfaces that can be used by this script.
  2. block script or code script, this affects how the script is edited.

Editing Scripts

Double click on the script file to open it for editing, for block and code scripts please refer to the following documentation:

Block Scripts-User Manual

Code Scripts-User Manual

Mounting Scripts

Mounting to a Module:

image-20240719145730470

image-20240719145743950

Mount to object:

Select the object you want to add script to, and choose Add Script in its inspector panel:

image-20240929154213472

image-20240719151758399

Again, you can select an existing script or create a new one.

Adding scripts using scripts:

We provide an interface that can mount scripts for entities:

Adding scripts:

image-20240719151930002

It is recommended that you use the Existing Scripts interface to confirm that the entity already has the same script before adding it.

image-20240719152647755

Uninstalling Scripts

To statically uninstall a script before starting the game, simply find the mount and click the minus sign:

image-20240719152520504

To uninstall the script dynamically after the game has started, use the Delete Script interface:

image-20240719152550242

Again, we recommend confirming that the entity does indeed mount the script to be deleted before deleting:

image-20240719152717738

Managing Script Files

If you create a new script when adding a script, it will automatically create a new ECA folder under the Assets folder to hold the new script:

image-20240719153237929

We also recommend that you use folders to categorize the scripts you create

Delete

Scripts can be deleted by using the shortcut Delete, or by right-clicking on the script in the asset:

image-20240719153352815

For entities that already have this script mounted, an error with a yellow exclamation point will appear:

image-20240719153705926

Copy

Using the shortcut keys Ctrl+C, Ctrl+V, or using the right-click menu, you can copy the script. The copied script name is the name of the original script plus (X), and X is the number of copies - 1.

image-20240719153524358

Rename

Using the shortcut F2, or using the context menu, you can rename the script.

image-20240719153932338

Scripts cannot be renamed, naming a script with the same name as an existing script will result in an error and cancel the renaming:

image-20240719154032997