Web Blocks Tutorial 1

Making blocks appear with code

① Hello block!

Did you know, in this Minecraft-like world, it is possible to change the world with code, as well as by hand?

➡ Go to webblocks.uk in your browser
(if you already have it open, please refresh your browser to ensure you begin with a fresh world)
➡ Press the ESC key on your keyboard

You will see the Console appear in front of you. This is a place you can type your code. The language you will be learning today is called JavaScript. Let's move our player into position first:

➡ Enter the following code, finishing with the Enter key:

resetPlayer()  

Did you see your player fall from the sky? Let's use the setBlock command to make blocks appear...

➡ Enter the following code, finishing with the Enter key:

setBlock(100,5,100,Stone)  

Did you see a new block appear in front of the Welcome sign? Can you guess what the numbers mean?

➡ Try changing the numbers (making them slightly smaller or bigger) to see what happens

💡 You can use the key to show the last command

You may have discovered that the numbers are in fact coordinates. In a 3D world we need 3 coordinates to represent a location. We call these 3 coordinates X, Y, and Z.

Block dimensions

The final piece of information is the block type. Here we are using the Stone type. Other block types such as Grass, Water and Air exist for you to use.

➡ Change the block type to make other kinds of block appear

② Hello multi-block!

We can also make multiple blocks appear at a time with the setBlocks command. Unlike the setBlock command, the setBlocks command takes 2 sets of co-ordinates instead one. This means 6 numbers are needed!

➡ Enter the following code, finishing with the Enter key:

setBlocks(100,5,100,100,10,100,Stone)  

Do you see a column in front of you?

➡ Try changing the numbers (making them slightly smaller or bigger) to see what happens

Can we figure out why we have 2 sets of co-ordinates?