โ›๏ธ Episode 4 ยท Improver ยท Functions

Run a List of Commands
Episode 4: Functions

A function is a list of commands Minecraft runs on demand. They let you build a whole sequence of actions and trigger it with one word.

๐Ÿ‘ถ Ages 10+ โฑ๏ธ ~50 mins โ›๏ธ Minecraft โœ“ Free workshop
๐Ÿ“œ .mcfunction โ–ถ๏ธ /function โ›“๏ธ Sequences ๐Ÿงช Trigger it
โญ
0 XP
Level 1
๐Ÿ”ฅ0
Your Progress 0 / 4 steps
Build it in our Datapack Studio too: lay out the crafting recipe, write your function and pack files, then export a real datapack zip in the browser with no install. Open the Minecraft Mod Studio →
๐Ÿ”ฅ
Ember says: anything you can type in chat, you can save in a function. One command in, a whole routine out.
1
๐Ÿ“œ
Write a Function
One command per line
Active
๐ŸŽฏ
Goal for this step

Create a .mcfunction file.

  • 1Make a file in data/<namespace>/function/ ending in .mcfunction.
  • 2Each line is one command, without the leading slash.
  • 3Blank lines and lines starting with # are ignored.
say Welcome to my datapack!
time set day
weather clear
โœ๏ธ
Fill in the Blanks
+15 XP
In a function file, each line is one without the slash.
๐Ÿง 
Knowledge Check
+15 XP
What kind of file is a function?
AA .mcfunction file
BA .json file
CA .png file
2
โ–ถ๏ธ
Run It
/function namespace:name
Locked
๐ŸŽฏ
Goal for this step

Trigger your function in-game.

  • 1Type /function mypack:hello (namespace:name).
  • 2All the commands run in order, instantly.
  • 3Handy for testing: run it again and again while you edit.
โœ๏ธ
Fill in the Blanks
+15 XP
You run a function with /function :name.
๐Ÿง 
Knowledge Check
+15 XP
How do you run a function called mypack:hello?
A/function mypack:hello
B/run hello
C/mypack hello
3
โ›“๏ธ
Chain a Routine
Build a sequence
Locked
๐ŸŽฏ
Goal for this step

Make a function that does several things in order.

  • 1Put commands one after another to build a routine.
  • 2A function can call another function by name.
  • 3Order matters: the top line runs first.
function mypack:clear_area
fill ~-5 ~ ~-5 ~5 ~5 ~5 minecraft:air
say The area is clear!
โœ๏ธ
Fill in the Blanks
+15 XP
A function can call another by name.
๐Ÿง 
Knowledge Check
+15 XP
Which line of a function runs first?
AThe top line
BThe bottom line
CA random line
4
๐Ÿงช
Test and Tidy
Small steps
Locked
๐ŸŽฏ
Goal for this step

Test each command on its own first.

  • 1Test commands in chat first, then paste the working ones into the function.
  • 2If a command errors, the ones after it still try to run. Check the log.
  • 3Give functions clear names so you can find them later.
โœ๏ธ
Fill in the Blanks
+15 XP
Test risky commands in chat before adding them to a .
๐Ÿง 
Knowledge Check
+15 XP
Why test a command in chat first?
ATo see it work before saving it
BIt is faster to type
CFunctions cannot be edited
๐ŸŽ‰โœจ๐Ÿ†๐ŸŽ‰
Commands on Demand!
You can bundle commands into functions. Next you make blocks and chests drop your own loot.
0
Total XP
1
Level
0
Best Streak
0%
Accuracy
Next: Episode 5: Loot Tables โ†’