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