Bedrock; Behavior Pack, manifest v2 · 3 min read

Bedrock functions: run commands from a file as the right executor

The function is a text file with command without the leading slash. Let's make a message and add a point, and then check why @s works from chat and requires an explicit executor in the command block.

LonelyCraft editors · Updated

The player assembles a redstone mechanism in a wooden workshop
Illustration: a player assembles a redstone mechanism in a wooden workshop. This is an artistic scene, not a snapshot of a specific server.

Create a package and file

In development_behavior_packs inside the com.mojang directory, create WorkshopFunctions. Save the manifest.json from the example in its root. Create functions/workshop/award.mcfunction nearby. The complete Windows development path is shown in the Add-Ons manual.

{
  "format_version": 2,
  "header": {
    "name": "WorkshopFunctions",
    "description": "Учебный пакет LonelyCraft",
    "uuid": "66714edc-cc70-438c-92d0-fbb09d781db5",
    "version": [
      1,
      0,
      0
    ],
    "min_engine_version": [
      1,
      21,
      0
    ]
  },
  "modules": [
    {
      "type": "data",
      "uuid": "420c5a52-d0b4-4467-8141-a805f1d2dd72",
      "version": [
        1,
        0,
        0
      ]
    }
  ]
}

Write two lines

Save the plain UTF-8 text with the .mcfunction extension, without the hidden .txt. There is no need for a slash at the beginning of lines. Activate the package in the test world with command; After editing the file, go to the menu and open world again.

scoreboard players add @s workshop_points 1
say Award function called
The function name is determined by the file path
Revision scheme: the function name is determined by the file path.Scroll the diagram horizontally.Open full-size diagram

Initialize the score and invoke the function manually

Execute the preparation command from the block below in the chat once. Then execute /function workshop/award three times. Expect three messages and the number 3 in the sidebar. If there is no message, the function was not found or was not loaded; if there is a message but no point, check the objective and performer.

/scoreboard objectives add workshop_points dummy
/scoreboard players set @s workshop_points 0
/scoreboard objectives setdisplay sidebar workshop_points
/function workshop/award

Consider creating an objective and changing a value. Bedrock counter.

Running from a command block: choose the player

The command block does not have player @s. Write execute as @p at @s run function workshop/award into it. Here as changes the player, and at transfers the position and dimension to the selected player. For our point increase, the performer is enough; at is useful for functions with relative coordinates.

@p is chosen relative to the execution location, not necessarily the button clicker. In multiplayer mechanics, use explicit selection of participants and tags. An automatic call via tick.json is executed every tick: do not transfer the issuance of a point there without a condition and protection against repetition. For the first project, leave it manually.

How to test a circuit before starting it all the time. command blocks.

Frequently asked questions

Is the slash needed in the file?

No. The slash is needed when entering /function in chat.

The function from the subfolder is not located?

The call name contains the path: functions/workshop/award.mcfunction → /function workshop/award.

Why doesn't @s work from a block?

The block is not a player. Assign an executor via execute as.

Views: … · One view per browser per day

Was this useful?Total score: …

One reaction per browser. Click again to remove it, or choose the other reaction.

Sources and documentation

constructionfunctionsbedrock

Read on

Bedrock functions: run commands from a file as the right executor — Lonely Craft