Using Minecraft Blocks as Buttons: Block-by-Block Tutorial Video in MakeCode for Minecraft

 

main

Strategy

The strategy for using Minecraft blocks as buttons to control a program is:

  1. Place the buttons on the screen in a place convenient to the player.
  2. In the block on-broken event, use the code that would have been in a on-chat command to do a sequence of actions,
  3. Replace the broken block with another of the same kind.

MakeCode Code

We modified the existing program described in Handy Timer — Block-by-Block Tutorial Video in MakeCode for Minecraft , to illustrate using Minecraft blocks as buttons. Only the changed code is described here.  This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

The placeButtons Function

The placeButtons function does exactly what its name implies: it places each button that will be used in lieu of an on-chat command. I like to place the buttons in front of the player within easy reach so that the player need not move to break a block (click a button). In this case we placed red concrete to do the same thing as the stop on-chat command, yellow for the reset command and green for the go command.
Place button code

Call the placeButtons Function

Once the function is built, it must be called from every code that initializes a screen. Here it is called from on start and from moveMe. As explained in the next section, it is also called from each block’s on-broken event.

on start and moveme

Code the on-broken Events

Each block being used as a button must have an on-broken event in which the same code as in the corresponding on-chat command should be run. I like to move the code to a function, which is called from both the on-broken event and the on-chat command. The advantage of putting the code in a function is that if it is modified, it need be changed in only one place.

Each on-broken event must also call placeButtons. Of course, an on-broken event really must replace only the broken button, but the advantage of calling the placeButtons event is that if you want to futz with the location of the buttons, it need be changed only in one place — always a good thing.

all buttons code

Get the Code

Handy Timer with Blocks for Buttons code is shared on Code Connection at this URL

https://makecode.com/_iwCgCd5bsFxY

To get and use the code, follow these steps.

Click the Import button import button , which is upper right in the Code Connection window just below the banner. This will open the window shown below.
Import choices

Click the Import URL button Import URL, which is on the right, to open the window shown below.

Import Copy link

Paste the URL supplied for the program you want to use in the space under the text “Copy the URL …”
import url with url

Click the Go ahead! button go ahead button.

The next window you will see will be the MakeCode window with the code downloaded from the URL. At this point, you can treat it like any other code, e.g., run it, save it locally, modify it, publish your changes or whatever else your heat desires.

We have tested several other methods of downloading the code using the URL, for example, pasting the URL in a browser. No joy. For more detailed instruction see our post How to Use Shared MakeCode on Microsoft Code Connection for Minecraft.

One thought on “Using Minecraft Blocks as Buttons: Block-by-Block Tutorial Video in MakeCode for Minecraft

  1. Pingback: Handy Timer — Block-by-Block Tutorial Video in MakeCode for Minecraft | We Code MakeCode

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s