串接子指令(as、at、if、unless…),為每個符合條件的實體執行一條指令,適用於 Java 與 Bedrock。
若要在麥塊 Java 26.2 中向每位玩家發送個人聊天訊息,請執行: /execute as @a run tellraw @s "This message is sent to each of you." 指令鏈中的每個子指令都會由左至右逐步縮小最終指令執行的對象或位置。可選擇一條已建立的指令(例如 /tellraw)作為結尾,或自行輸入任意指令。
每個子指令會由左至右逐步縮小最終指令執行的對象或位置。
/execute as @a run tellraw @s "Hello from execute!"指令輸出針對Java 26.2和Bedrock 1.26.40產生,並已於2026-07-10在遊戲內完成貼上驗證。
Bedrock 1.26.40(自 1.19.50 起)支援與 Java 相同的 /execute 子指令鏈——實際差異在於條件和維度中的 id 形式,以及結尾指令的寫法:
| 項目 | Java 26.2 | Bedrock 1.26.30 |
|---|---|---|
| 同一條指令鏈 | /execute as @a run tellraw @s "This message is sent to each of you." | /execute as @a run tellraw @s {"rawtext":[{"text":"This message is sent to each of you."}]} |
| 子指令 | as · at · positioned · facing · align · anchored · in · if · unless | 兩個版本相同 |
| 維度 id(in …) | minecraft:overworld | overworld |
| 方塊 id(if block …) | minecraft:diamond_block | diamond_block |
/execute 會在修改過的環境中執行另一條指令——例如以不同的實體身分、在某個位置,或僅在條件成立時執行。它是指令方塊與資料包邏輯的核心。
子指令會由左至右套用。「execute as @a at @s run …」會為每位玩家各執行一次最終指令,並定位於各自的位置。加上 if/unless 可讓指令僅在某個方塊、實體或分數符合條件時執行。
Bedrock 支援相同的子指令串接(as、at、positioned、if、unless…)。此處的目標使用 @p/@s/@a/@r 或玩家名稱;「輸入任意指令」選項可讓你在任一版本上執行任意結尾指令。