Events and Scripts

July 4, 2022

Events and Scripts

Introduction to Global Events

The event editor under the game settings can edit events related to the entire game process, including: when waiting for the player to enter the game, when waiting for the game to start, when the game is ready to start, when the game officially starts, when the game ends, when the game When exiting.

Global Script

Introduction to Global Script

When the game starts, it will automatically execute a script file named main.lua, which is usually used as a script entry in the global environment.

According to the running environment of the script, we divide the code script into three major categories. The first category is server scripts that run on the server; the second category is client scripts that run on the client; the third category is public scripts that can be run by both the client and the server.

Global Script Management

The editor provides three script warehouses: server-side script, client-side script, and public script. You can distinguish and manage these three types of code scripts more intuitively. There will be a script named main.lua in each script warehouse. This script will be automatically loaded in the runtime environment corresponding to the script warehouse. Its main function is to determine whether other code scripts under the script warehouse need to be loaded immediately.

Script Execution Timing

On the server side, the default execution order when the server starts is: Global main script> Server side script repository main script> Public script repository main script..

On the client, the default execution sequence when the client starts is:Global main script> Client script repository main script> Public script repository main script..

If you have special requirements, you can also adjust the execution sequence of the server main script, client main script, and public main script in the global main script.

Load other Scripts

In the main script in the script warehouse, you can directly use require to load the script that needs to be loaded.

Note that depending on the script repository, the starting path of require is different. The starting path in the server script repository is “script_server.”, the client repository is “script_client.”, and the public repository is “script_common.” , The subsequent path is the location path of the directory list where the script to be loaded is located.

for example:
Create a test script in the server warehouse:

Then load the test script in the main script of the server-side script warehouse: