Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

script api

unknown edited this page Nov 23, 2020 · 1 revision

Scripting API Documentation

For Advanced Users Only

Introduction

ElementZero supports the scripting system.

For more information, and basic documentation, for the vanilla scripting API, click here.

In addition to behavior packs, scripts can also be added to a dedicated scripts directory.

Using scripts

In order to enable scripting, you need to turn on experimental features. This can be done in custom.yaml.

The entrypoint for dedicated scripts is scripts/index.js. You can also put them in a behaviour pack.

Develop scripts

Bedrock.dev currently has the best, most up to date documentation for the "vanilla" scripting.

ESM

A very useful feature which EZ adds is ESM (short for ES Modules)

This means you can use import statements (see here.

Import for side effects only

From index.js, you can import other scripts for their side effects only, so their code is ran.

An example of an index.js file could be:

import "./combat/index.js"
import "./info/index.js"
import "./mobReward.js"

console.log("Import finished");

Here, ./combat/index.js could have even more import statements, so you can build up a folder structure. This is unnecessary, but can help make your scripts directory neater.

Import EZ modules

If a certain script requires it, you can also import functions from other EZ plugins.

Some plugins which add scripting support are: Economy, BossBarSupport and ChatAPI

You can use the import statement in the following way:

import {
    whatToImport,
    whatElseToImport
} from "ez:modulename";

You can also import and export declarations from your own scripts. In this case, you would replace "ez:moduleName" with "./fileName.js".

Common functions

More info here

console.log(message)

Logs a message to the console. message is any string you like.

executeCommand(command, callback)

Executes a command. command is a string containing the command you wish to execute. Note: do not start the string with /.

broadcastEvent

createEventData

listenForEvent

registerEventData

Components

More info here

Events

More info here