/scriptevent

From Minecraft Wiki
Jump to navigation Jump to search
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

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; @here can be used to mention all players.

Result

[edit | edit source]

CommandTriggerBedrock Edition
Anythe arguments are not specified correctly Unparseable
OtherwiseSuccessful

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;
});

Code source

History

[edit | edit source]
Bedrock Edition
Beta APIs
(Experimental)
Preview 1.19.60.22Added /scriptevent behind the "Beta APIs" experimental toggle.
1.20.30Preview 1.20.20.20/scriptevent is no longer behind "Beta APIs" experimental toggle.

See also

[edit | edit source]
  • /script— debugging options for GameTest Framework
[edit | edit source]
[edit | edit source]