チャットコマンドを実行する player.runChatCommand
ひとことで言うと
コード内でチャットコマンドを実行します。
ブロックとコード
チャットコマンド"jump"を 実行する
ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。
player.runChatCommand("jump")player.run_chat_command("jump")引数(ひきすう)
引数とは、ブロックの中で自分で選んだり入力したりする部分のことです。
| 名前 | 選べる値 | 意味 |
|---|---|---|
| command | 文字列 | 実行するチャットコマンド。たとえば:「jump」 |
使用例
Let's say you have a chat command in your project that makes your agent move forward and place a block:
JavaScript
player.onChat("placeforward", function () {
agent.move(FORWARD, 1);
agent.place(BACK);
});Python
def on_on_chat():
agent.move(FORWARD, 1)
agent.place(BACK)
player.on_chat("placeforward", on_on_chat)You can reuse this chat command in other parts of your code to have your agent build a row:
JavaScript
player.onChat("row", function () {
agent.teleportToPlayer();
for (let i = 0; i < 5; i++) {
player.runChatCommand("placeforward");
}
});Python
def on_on_chat():
agent.teleport_to_player()
for i in range(5):
player.run_chat_command("placeforward")
player.on_chat("row", on_on_chat)