/scriptevent
< Commands
This feature is exclusive to Bedrock Edition and Minecraft Education.
/scriptevent| Permission level required |
1 |
|---|---|
| Restrictions |
Cheat only |
{
"title": "<code>/scriptevent</code>",
"rows": [
{
"field": "1",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "(link to Option article, displayed as Cheat) only<br>",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Triggers a script event with an ID and message.
Syntax
scriptevent <messageId: string> <message: message>
Arguments
messageId: string: basic_string
- Must be a string. Must be namespaced and use of the minecraft namespace is invalid (e.g.
/ give:coal,/ my_scripts:spawn_sheep)
message: message: CommandMessage
- Optional argument. Max length 256 characters. It is a greedy phrase string argument (taking the rest of the command as the string argument). Can include spaces as well as target selectors. The game replaces entity selectors in the message with the list of selected entities' names, which is formatted as "name1 and name2" for two entities, or "name1, name2, ... and namen" for n entities.
@<player name>can be used to mention a player;@herecan be used to mention all players.
Result
| Command | Trigger | Bedrock Edition |
|---|---|---|
| Any | the arguments are not specified correctly | Unparseable |
| Otherwise | Successful |
The command by itself does not directly affect anything in the game, but can trigger an event in any add-ons applied to the world/server.
Output
| Command | Edition | Situation | Success Count |
|---|---|---|---|
| any | Bedrock Edition | On fail | 0 |
| On success | 1 |
Example
- To evoke an event handler with the ID wiki:example and the message "Example Message":
/scriptevent wiki:example Example Message
- Example JavaScript code for use in the scripting API:
import { system } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe((event) => {
const {
id, // returns string (wiki:example)
initiator, // returns Entity
message, // returns string (Example Message)
sourceBlock, // returns Block
sourceEntity, // returns Entity
sourceType, // returns MessageSourceType
} = event;
});
History
| Bedrock Edition | |||||||
|---|---|---|---|---|---|---|---|
| Beta APIs (Experimental) | Preview 1.19.60.22 | Added /scriptevent behind the "Beta APIs" experimental toggle. | |||||
| 1.20.30 | Preview 1.20.20.20 | /scriptevent is no longer behind "Beta APIs" experimental toggle. | |||||
See also
/script— debugging options for GameTest Framework