/scriptevent
< Commands
Not to be confused with Commands/script.
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 Cheat 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
[edit | edit source]scriptevent <messageId: string> <message: message>
Arguments
[edit | edit source]messageId: string: basic_string
- Must be a string. Must be namespaced and use of the minecraft namespace is invalid (e.g.
/scriptevent give:coal,/scriptevent my_scripts:spawn_sheep)
message: message: CommandMessage
- Optional argument. Maximum length is the C++ max string length. 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
[edit | edit source]
| 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
[edit | edit source]| Command | Edition | Situation | Success Count |
|---|---|---|---|
| any | Bedrock Edition | On fail | 0 |
| On success | 1 |
Example
[edit | edit source]- 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
[edit | edit source]| 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
[edit | edit source]/script— debugging options for GameTest Framework
External links
[edit | edit source]- "
/scripteventCommand" – Microsoft Learn, December 12, 2024.