Minecraft:Commands/scriptevent: Difference between revisions
From SAS Gaming Wiki
More actions
Remove broken links to missing pages |
Sync: updated from Minecraft |
||
| (One intermediate revision by the same user not shown) | |||
| Line 6: | Line 6: | ||
| cheat = y | | cheat = y | ||
}} | }} | ||
Triggers a script event with an ID and message. | Triggers a [[Minecraft:Scripting|script]] event with an ID and message. | ||
==Syntax== | ==Syntax== | ||
| Line 24: | Line 24: | ||
{{Result table}} | {{Result table}} | ||
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. | The command by itself does not directly affect anything in the game, but can trigger an event in any [[Minecraft:add-ons]] applied to the world/server. | ||
==Output== | ==Output== | ||
| Line 47: | Line 47: | ||
**{{Code|code=/scriptevent wiki:example Example Message}} | **{{Code|code=/scriptevent wiki:example Example Message}} | ||
*Example JavaScript code for use in the scripting API: | *Example JavaScript code for use in the scripting API: | ||
<syntaxhighlight lang="javascript" line="1"> | <syntaxhighlight lang="javascript" line="1">import { system } from "@minecraft/server"; | ||
import { system } from "@minecraft/server"; | |||
system.afterEvents.scriptEventReceive.subscribe((event) => { | system.afterEvents.scriptEventReceive.subscribe((event) => { | ||
| Line 59: | Line 58: | ||
sourceType, // returns MessageSourceType | sourceType, // returns MessageSourceType | ||
} = event; | } = event; | ||
}); | });</syntaxhighlight>[https://wiki.bedrock.dev/scripting/script-server.html Code source] | ||
</syntaxhighlight>[https://wiki.bedrock.dev/scripting/script-server.html Code source] | |||
==History== | ==History== | ||
| Line 81: | Line 79: | ||
{{Navbox commands}} | {{Navbox commands}} | ||
de:Befehl/scriptevent | [[Minecraft:de:Befehl/scriptevent]] | ||
zh:命令/scriptevent | [[Minecraft:zh:命令/scriptevent]] | ||
Latest revision as of 11:03, 11 June 2026
Template:Distinguish Template:Exclusive Template:Infobox command Triggers a script event with an ID and message.
Syntax
scriptevent <messageId: string> <message: message>
Arguments
- Must be a string. Must be namespaced and use of the minecraft namespace is invalid (e.g. Template:Command, Template:Cmd)
- Optional argument. Maximum length is the C++ max string length. Template:Arg desc
Result
Template:Result table Template:Result table Template:Result table Template:Result table
The command by itself does not directly affect anything in the game, but can trigger an event in any Minecraft:add-ons applied to the world/server.
Output
| Command | Edition | Situation | Success Count |
|---|---|---|---|
| any | Minecraft:Bedrock Edition | On fail | 0 |
| On success | 1 |
Example
- To evoke an event handler with the ID wiki:example and the message "Example Message":
- Example JavaScript code for use in the scripting API:
<syntaxhighlight lang="javascript" line="1">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;
});</syntaxhighlight>Code source
History
See also
- Template:Cmd— debugging options for GameTest Framework