Create a command to teleport super high into the air. Learn how you can pass a number into a command to change how it works.
In this project we are going to learn how to create a command to make your player teleport super high in the air.
First, open Minecraft Education Edition, login, create a new world and open the Code Builder.
To create a new Minecraft coding project you will need to follow these steps:
Add a on chat command block and rename it it to "jump". Then add a teleport to block and set the y (up) value of the position block to be 100.
player.onChat("jump", function () { player.teleport(pos(0, 100, 0)) })
When this code runs it will teleport your player 100 blocks above your current position.
A position represents a location in the Minecraft world. Positions are used in many blocks and commands to spawn mobs, fill blocks and more.
A position is represented by 3 numbers, x, y, and z:
The numbers for x, y, and z are the coordinates (a coordinate is also known as a direction or an axis) of the position.
There are two kinds of positions: a relative position and a world position.
Go to your Minecraft world and run the jump command. You will see that your player gets teleported high into the sky.
To run a Minecraft command follow these steps:
Next let's change our "jump" command so that we can specify how high to jump. We will pass a number into the command and use that number to set the y (up) value in the teleport block.
Open the Code Editor and click the + button on your "jump" command. This will create a new variable called "num1". Then get the num1 block from the Variables toolbox and put it into the y value in the position block.
player.onChat("jump", function (num1) { player.teleport(pos(0, num1, 0)) })
Now run the jump command again but this time put a space and then a number after "jump". For example to make your player jump 50 high type this in the chat command "jump 50".
Try some other numbers with the jump command and see how it changes how high you jump!
To run a Minecraft command follow these steps: