$$ \newcommand{\floor}[1]{\left\lfloor{#1}\right\rfloor} \newcommand{\ceil}[1]{\left\lceil{#1}\right\rceil} \renewcommand{\mod}{\,\mathrm{mod}\,} \renewcommand{\div}{\,\mathrm{div}\,} \newcommand{\metar}{\,\mathrm{m}} \newcommand{\cm}{\,\mathrm{cm}} \newcommand{\dm}{\,\mathrm{dm}} \newcommand{\litar}{\,\mathrm{l}} \newcommand{\km}{\,\mathrm{km}} \newcommand{\s}{\,\mathrm{s}} \newcommand{\h}{\,\mathrm{h}} \newcommand{\minut}{\,\mathrm{min}} \newcommand{\kmh}{\,\mathrm{\frac{km}{h}}} \newcommand{\ms}{\,\mathrm{\frac{m}{s}}} \newcommand{\mss}{\,\mathrm{\frac{m}{s^2}}} \newcommand{\mmin}{\,\mathrm{\frac{m}{min}}} \newcommand{\smin}{\,\mathrm{\frac{s}{min}}} $$

Prijavi problem


Obeleži sve kategorije koje odgovaraju problemu

Još detalja - opišite nam problem


Uspešno ste prijavili problem!
Status problema i sve dodatne informacije možete pratiti klikom na link.
Nažalost nismo trenutno u mogućnosti da obradimo vaš zahtev.
Molimo vas da pokušate kasnije.

Project Task - Planting Trees

Events are occurrences, which are usually results of something the user did (clicking the mouse, pressing keys on the keyboard, drag and drop, etc.). An event causes a reaction. An event in computer science is an action detected (performed) by a computer. For example, by clicking the mouse, we open an application, when it starts raining people open umbrellas. In programming, an event handler is the part of the program (function) which is activated as a result of some event. In MakeCode event handlers are blocks which usually start with the word on:

_images/311.png

We will use an event to simulate planting trees and displaying the current position of the character in the Minecraft world, by adding the command position.

Stage 1.

Thinking about the task: The character interacts with the world by moving around, i.e. trees are planted. The character plants trees by moving around the Minecraft world. Sending a message (through chat) displays the current position of the character.

Stage 2

Open Code Builder (by pressing the key C); an editor window will appear where you can stack blocks.

To start the chat, or more specifically, to trigger an event which will display character’s current position, we need to drag the block onchat from the category Basic to the work surface, and then type the word position into the input field of this block.

Within this block, we need to add blocks that will say the current position. To say any message (e.g. My current position is:) we need to use the block say from the category Player.

The character’s (player’s) position is stored in the block position from the category Player. Since we want to display the position of the player in chat, we need to use the block string form the category Pozicija. Instead of the option position, we will insert the block position into the field:

_images/41.png

Let’s test this part of the code by clicking the button Play.

After testing the program, we can see that we got what we wanted. When the user presses the key T, opens the chat and types in the message position, player’s current position in the world will be displayed.

_images/431.png _images/421.png

Now we need to create an event for the character, which will enable it to plant trees in the Minecraft world with its movement. This will be achieved with the block walk. From the drop-down list of this block we will choose the option walk:

_images/441.png

And finally, we need to place the block place from the category Blocks within this block. We use this block to place (or in our case plant) a tree. From the drop-down list of this block we will choose the block which represents a tree:

_images/461.png

In the at part of the block, where we need to define the position of the block we want to place in the world, we will leave all three values to be 0 nula. This will allow the trees to be planted in the same plane the character is located.

After all the changes, the part of the code for planting trees is presented in the figure below:

_images/491.png

Stage 3

Testing the program. Click on the button Play.

_images/48.png

Once we have tested the program, we can conclude that it did what we wanted. The character is planting trees by moving around.