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.
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.
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.
Events that can only be run under the server platform
Static Scripts
Scripts are all supported to be configured as static scripts:
Static scripts will always run under the global module.
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.
With the static script New ECA.eca mounted on the global entity, the internal event is triggered twice. (This configuration is not recommended.)
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
Select New when mounting the script:
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:
- server script or client script, which affects the events and interfaces that can be used by this script.
- 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:
Mounting Scripts
Mounting to a Module:
Mount to object:
Select the object you want to add script to, and choose Add Script in its inspector panel:
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:
It is recommended that you use the Existing Scripts interface to confirm that the entity already has the same script before adding it.
Uninstalling Scripts
To statically uninstall a script before starting the game, simply find the mount and click the minus sign:
To uninstall the script dynamically after the game has started, use the Delete Script interface:
Again, we recommend confirming that the entity does indeed mount the script to be deleted before deleting:
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:
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:
For entities that already have this script mounted, an error with a yellow exclamation point will appear:
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.
Rename
Using the shortcut F2, or using the context menu, you can rename the script.
Scripts cannot be renamed, naming a script with the same name as an existing script will result in an error and cancel the renaming: