run Chat Command With Arguments

Runs a chat command in your code with arguments. The argument is a string used by the code inside your ||player:run chat command|| code block.

player.runChatCommandWithArguments("jump", "5");

Parameters

  • command: the chat command to run, like: “jump”
  • arg: a string containing all the arguments you wish to give to the chat command

Example

Let’s say you have a chat command in your project that makes your agent build a row of blocks of variable length:

player.onChat("row", function (length) {
    for (let i = 0; i < length; i++) {
        agent.move(FORWARD, 1);
        agent.place(BACK);
    }
})

You can reuse this chat command in other parts of your code to build a square, for example:

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

The new chat command named square uses the row chat command to place rows of 5 blocks. The row command is repeated 4 times to make a square that is 5 blocks wide. Each time your agent places a row of blocks and is then told to turn and move to make the next side of the square.

See also

||player:run chat command||, ||player:on chat command||