iPad Pro 2018 Takes on Surface Studio 2 Running MakeCode for Minecraft

Here I compared the iPad Pro and the Surface Studio 2 relative performance running Grandma’s Game of Life  Blinker pattern. It is a good visual measure of the relative speed of the two implementations of MakeCode for Minecraft Education Edition on these two computers. See the video of Blinker test below.
2018-12-02_21-15-34

New iPad Pro Inspired My New Surface Studio

I was depressed that my new — and my old — iPad Pro ran circles around my old  Surface Studio when running the performance hogging MakeCode for Minecraft program  described in Grandma’s Game of Life in MakeCode for Minecraft . I found such a topsy-turvy world to be quite depressing. Since I always crave the latest and greatest computer, I assumed a new Studio was in my near future, so  I decided to make it sooner than later.

My New Surface Studio 2

On the Saturday after Black Friday, I walked over to the Houston Galleria Microsoft Store to explore buying a Surface Studio 2. I told the Microsoft Store person that I wanted to set up the new Studio 2 and test it with my MakeCode for Minecraft app before taking it home. The results are sown in the video below. I wept.

The iPad Pro and the Surface Studio 2  are running Grandma’s Game of Life, specifically the Blinker pattern. It is a good visual measure of the relative speed of two computers. I have run many other patterns to compare — all with the same results: iPad wins.

Oh, well, I took the Studio 2 home anyway. I want to test it against my old studio. And, I have a month to return it.

Don’t Judge  a Computer on Just One Test Program

I’ve done enough computer-performance testing in my life to fill volumes. I understand that one program is an insufficient test. Rather, one needs a balanced load that represents the sphere of applications and users, blah, blah, blah…… But, in my case, I only cared about this one program — and, the Studio 2 results are dismal.

Surface Studio Has Redeeming Features

On the other hand, developing on the iPad even with the 12.9 inch screen, for the size programs I do, is simply not feasible. And, I love that touch  Studio display — but do I need a new Studio? More exploration is needed.

Code Part 5 — Event Processing for Riding the Rail in MakeCode for Minecraft

 

The Code that Processes Events in Response to Player Actions

The code in the not-grayed out area of the screenshot below processes events triggered by the player when something is clicked or tapped, for example, the Spawn Position or a control block.

code part 5

Loading the Hotbar

hotbar

After clearing it, the player’s Hotbar is loaded by the function shown below with the following items:

  • minecart — must be selected before clicking or tapping to place a minecart on the rail.
  • unpowered rail — useful when repairing square corners that sometimes appear when the rail is generated.
  • power rail  — useful if the player accidentally breaks a powered-rail block.
  • grass — useful if the player accidently breaks grass. I do this when being too zealous with a long tap (tap and hold).
  • minecart with hopper — helps to keep some of the debris off the rail.

hotbar load

Placing a Minecart and Spawning a MOB in the Minecart

Riding the Rail is made especially fun because it is easy for a player to place a minecart on the rail with a MOB in it. How the player does this depends on whether she is using touch or a mouse to click on Minecraft objects. The two ways are:

  • Using a mouse, with a minecart selected in the Hotbar, right click on Spawn Position when it is clear of obstructions (e.g., another minecart, MOB, player). This will place a minecart at the Spawn Position and generate an on-minecart-used event, which places a MOB in the just placed minecart.
  • Using touch requires the following two-step process:
    1. With a minecart selected in the Hotbar, quick tap on the Spawn Position when it is clear of obstructions (e.g., another minecart, MOB, player). This will place the minecart; however, no on-minecart-used event will be triggered. Because the event is not triggered, no MOB is placed in the minecart. Touch quick tap is equivalent to mouse right click.
    2. With a minecart selected in the Hotbar, tap and hold on the brown block long enough to break it. This will trigger an on-minecart-used event, which will result in placing a MOB in the minecart that was placed in step 1. Touch tap and hold is equivalent to mouse left click. See below for more information about the role of the brown block.

buttons for code

On-minecart-used Event

The on-minecart-used event, which is triggered as described in the previous paragraphs, calls a function to spawn a MOB at the Spawn Position, but only if the Boolean variable b_spawn_at_spawn_positoiin is true. This Boolean is toggled by the gray/black block to enable placing a minecart with or without a MOB, respectively (see below).
on minecart used

The on-minecart-used event spawns a MOB at the Spawn Position unless the gray/black block is black. The function that does this is spawn_at_Spawn_Position, which first calls the get_MOB_index function to get the index into the spawn list of the next or a random MOB to be used.  It then spawns the MOB from he spawn list at index index_MOB. The MOB is spawned at Spawn Position.

spawn at spawn position

Brown Control Block Actions

As shown by the code in the following graphic, when the brown block is broken and triggers an on-block-broken event, the block is  restored — and, according to the code below nothing else happens. Hmmm.

button brown code

What actually happens depends on whether the player is using a mouse or touch. If using a mouse, there is no need to break the brown block — ignore it. You can break it all day long but nothing will happen.

If using touch, tap and hold on the brown block long enough to break and a minecart is selected in the Hotbar, an on-minecart-used event will be generated, which will place a MOB at the Spawn Position. Weirdly, no minecart is placed in spite of the on-minecart-used event being generated.  If a minecart is at the Spawn Position, the MOB will be placed in it. The usage here is for the player to short tap the Spawn Position to place a minecart and tap and hold the brown block to generate the on-minecart-used event to place a MOB in the cart.

Gray/Black Control Block Actions

When broken the gray block will be replaced with a black and vice versa; thus causing the block to toggle between gray and black.

button gray black

While it is gray, a MOB will be spawned at the Spawn Position each time the on-minecart-used event is fired. While the block is  black, no MOB will be spawned when the on-minecart-used event fires; thus, enabling a minecart to be placed anywhere on the rail without a MOB being spawned at the Spawn Position. These actions are accomplished by setting a Boolean variable to true or false depending whether or not a MOB should be spawned when the on-minecart-used event fires.

Green Control Block Actions

When the green block is broken, the next MOB in the list is spawned at a random position inside the rail. The broken green block is restored.
button greencode

The on-green-concrete-block-broken event spawns a MOB at a random position inside the rail. The function that does this is spawn_at_random_position.
spawn at random position

The function get_MOB_index

This function is called by both the functions that spawn MOBs. The variable index_MOB is generated by get_MOB_index in the manner determined by the variable b_spawn_in_random_order, which was determined by the on-chat command the started the program.

If the MOBs are to be spawned in random order, the index_MOB is picked as a random number between 0 and the length of the spawn list minus 1.

If the MOB is to be spawned in the order in which they are in the spawn list (sequentially) , index_MOB is set to spawned_MOB_counter modulo length of spawn list. This nifty piece of math guarantees that index_MOB is 0 to length of spawn list minus 1.

Whether random or sequential, spawned_MOB_counter is incremented by 1.

get mob index

Sandstone/Redstone Control Block Actions

When the sandstone block is broken, the redstone blocks under the rail are replaced with sandstone blocks; thus, removing power from the rail. The sandstone control block is replaced with a redstone control block.

When the redstone block is broken, the sandstone blocks under the rail are replaced with redstone; thus, restoring power to the rail. The redstone control block is replaced with a sandstone control block.

The code below that accomplishes this using the northwest and southeast rail corners,  which are diagonally opposing to define the area in which to find blocks to replace. The corners array was defined earlier in The Code Part 3 — Build the Field for Riding the Rail in MakeCode for Minecraft.
button snadstone

Code Requires a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_bPdMMvgg5Mjw

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.

Code Part 4 — Spawn List for Riding the Rail in MakeCode for Minecraft

 

The Code that Builds the Spawn List for Riding the Rail

The code in the not-grayed-out area on the bottom left and near the middle of the screenshot below initializes the spawn list for a particular run of Riding the Rail. It does this by using the information specified in the on-chat command that launched the program .

code part 4

The Spawn List

As depicted in the drawing below, the spawn list is the link between the on-chat commands (e.g., animals) that start the program and the player-initiated events that enable interaction, for example,  the on-minecart-used event picks a MOB from the spawn list and spawns it in the minecart.

spawn List Big Picture.jpg

The on-chat-commands code put MOBs into the spawn list, which can be any length. Player-initiated events cause MOBs in the spawn list to be used either sequentially or randomly, depending on the player-choice in the initiating on-chat commands. If the MOBs are being used sequentially, when the last MOB in the list is removed, the selection will start over at the beginning of the list. MOBs are never removed from the list.

The variable mobs_to_spawn_list is a list that is initialized the code described in the post. In this post mobs_to_spawn_list is referred to by the short name “spawn list.” The spawn list is set to empty in the function init_beginning, which must be called before the main function described here, which is add_mobs_to_spawn_list_by_source. Note that earlier during coding of Riding the Rail and writing these posts describing the code, the name of the function was ended with “by_method” instead of “by_source” as it is now. It’s the same function.

Add MOBs to Spawn List by Source

The function “run” was described in Code Part 2 — on-Chat Commands for Riding the Rail in MakeCode for Minecraft.  It calls a function that adds MOBs to the spawn list depending on the argument num1 (aka spawn_list_source_of_mob which specifies the source of MOBs and can have values 0 to 3. The following four on-chat commands calls run with the appropriate arguments:

  • 0 — “selected”
  • 1 — “animals”
  • 2 — “monsters”
  • 3 — “all”

This post describes the function in the graphic below add_mobs_to_spawn_list_by_source and the functions it calls. The function is essentially a switch that calls different functions depending on the value of the variable spawn_list_source_of_mobs (aka MOB  source) as follows:

  • If MOB source is 0, the called function is select_mobs_to_spawn, which is modifiable by the player and will be described after all the simpler functions.
  • If MOB source is 1, the called function is add_animals_to_spawn_list.
  • If MOB source is 2, the called function is add_monsters_to_spawn_list.
  • If MOB source is 3, the functions for both animals and monsters are called.
  • If MOB source is any other valu9e, a error message is said.

add mobs by source

Function to Add Animals to Spawn List

In the last block this function calls add_mob_list_to_spawn_list, which does the work of adding one list to another. The preceding three statements set the variables used by the called function. The variable aList is the list to be added, which in this case is set to animalList (initialized when Riding the Rail starts and described below). The variable number_of_each_MOB_to_add is set to 1 here because only one of each animal type is needed. The variable number_of_MOB_types_to_spawn is set to the length of animalList because all animals are wanted.

add animals

Function to Add Monsters to Spawn List

The function to add the monsters list to the spawn list is similar to the one to add animals, except of course, it adds uses monsterList instead of animalList.

add monsters

The Animal List and Monster List

The lists animalList and monsterList  are initialized when the program starts. The on-chat command “animals” places all the animals in animalList in the spawn list, “monsters” places all the monsters in monsterList in the spawn list, and “all” puts both in the spawn list. These lists are also available for use for the advanced player using the “selected” on-chat command.
MOB lists

These lists can be modified by the player. For example, the player might want the items in the lists to be in a different order. She might want to exclude those MOBs that are not suitable for riding in a minecart (e.g., endermen, bats). In other situations, some monsters are not  available in the version of Minecraft being used. For example, as of this writing, only the first three monsters — shulker, vindicator and evoker — are available in Minecraft Education Edition. The other monsters should be removed from the list to avoid spawning “invisible” monsters, which is what will appear to happen if the unavailable monsters are left in the list and are used in the spawn list. Shulker, vindicator and evoker are the first three monsters in the monsterList so that they will be easier to retain and/or use by Education Edition players.

Player-Modifiable Function to Select MOBs to be Spawned

The function select_mobs_to_spawn  is provided for advanced players who want

  • complete control over which MOBs available to be spawned,
  • the MOB order in the spawn list and
  • the number of each to be used.

The function can have any number of sections, which are each terminated by a call to one of the functions add_mob_list_to_spawn_list or add_one_MOB_type_to_spawn_list. The sections can be in any order and more than one of each section type can be included in the function.

select mobs to spawn

The first section shown above adds animal types from animalList starting with index 0 and adding  number_of_MOB_types_to_spawn to the list . The second section is similar but uses the monsterList to add monsters. The last three sections each add one MOB type to the spawn list, which is specified by the variable MOB_to_add. The number to be added is specified by number_of_each_MOB_to_add.

Functions to Add MOBs to Spawn List

The function select_MOBs_to_spawn above terminates each section with a call to one of the following functions:

  • add_one_MOB_type_to_spawn_list or
  • add_mob_list_to_spawn_list.

The first function adds the MOB specified by the variable MOB_to_add to the spawn list number_of_each_MOB_to_add times.

add one type

This function adds number_of_mobs_from_list MOBs from aList to the spawn list. If number_of_mobs_from_list is less than the length of the list, all the MOBs in aList are added. the variable aList was set before this function was called to be either animalList or monsterList. By using the math block min (minimum) of the length of the list and the number_of_MOB_types_to_spawn, the code guarantees that it will not try to add more MOBs than are the aList.

add mob list

Output  Spawn List Information

Finally, messages are said to the player that provide the following information:

  • the number of MOBs in the spawn list. This is particularly helpful to the player who is learning to use “selected” MOB source to verify that the modified function does select the expected number of MOBs.
  • the spawn method: sequential or random.
  • a reminder to the player to select minecart in the Hotbar before clicking or tapping to spawn a minecart and MOB.

say number and surce

Code Requires a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_bPdMMvgg5Mjw

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.

Code Part 3 — Build the Field for Riding the Rail in MakeCode for Minecraft

 

The Code that Builds the Field for Riding the Rail

The code in the not-grayed-out area near the middle of the screenshot below builds the field (e.g., fence, rail and control buttons). 

code part 3

All the on-chat commands that start the program (described in Part 2), end by calling two functions:

  • First, they call the function init_beginning, which is the centerpiece function (described below)  that prepares the Minecraft world and sets variables to their initial values. init_beginning and the functions it calls are described in the post.
  • Second, they call one of the two function that prepare the spawn list according the specification of the on-chat-command that launched the program. (see Part 4).

The function init_beginning

The function init_beginning performs the following actions:

  • Moves the player to a new position by calling the function MoveMe.
  • Sets the position variable “center” to be where the player is initially standing.
  • Initializes the spawn list to be an empty list (array).
  • Sets the spawned_MOB_counter to 0. This counter will be incremented each time a MOB is spawned from the spawn list and, if the MOBs are to be spawned sequentially, will be used as an index into the spawn list to select the next MOB.
  • Initializes the Boolean variable b_spawn_at_Spawn_Position to true. This variable will later be used to decide whether to spawn a MOB at the Spawn Position or at a random position inside the rail.
  • Calls the function init_sides_and_corners, which sets several variables that provide position and size information about the fence and the rail.
  • Launches “fence,” which is an on-chat command that builds the fence. An on-chat command is used instead of a function so that the fence will be built at the same time as the rail is being laid, thus speeding up the program.

init beginning

  • Calls the function lay_redstone_and_rail, which builds the powered  rail.
  • Calls the function lay_corner_blocks to place the four corners of the rail. The corners must be placed after the four sides  (Minecraft requirement).
  • Calls the function put_stuff_in_player_inventory to put items that may be useful  (e.g., minecarts) in player inventory.
  • Calls the function set_buttons_and_spawn_position to place the four blocks that will serve as control buttons and to define the variable spawn_position to one block west of the northwest corner of the rail square.
  • Places a sunflower, which always faces east, just inside the fence so that the coder can conveniently know directions when building the rail. The sunflower is near the northwest corner of the fence.
  • Finally, this function teleports the player to a convenient position near the control buttons and the Spawn Position.

The Functions moveMe and setCenter

The function MoveMe, which is called by init_beginning (see prior section), moves the player 200 blocks east and to the ground. The new MakeCode ground block could have been used to do this. MoveMe calls setCenter, which sets the variable “center” to the player position. Riding the Rail code does not depend on the position of the player except for initially setting the variable “center.” After center is set, the player can move anywhere for a better view of the action.

The on-chat command “moveMe” is provided in case a player wants to move after a game. After a particular run of Riding the Rail, the MOBs can be noisy (I am especially distracted by the disgusting noise that Shulkers make) so I move to a quite place.

moveme and setcenter

Initialize Sides and Corner Positions

The function init_sides_and_corners, which is called by init_beginning, sets a number of variables that are used in fence and rail building. Notice that rail_corner and fence_corner both refer to a northwest corner, which when the player is facing east, is down and to the left of center so both adjustments from center are negative to get to a northwest corner. This function calls init_rail_corner_lists, which will be described below.

init sides and corners

On-chat command to build he Fence

The on-chat command “fence” is launched by init_beginning to build the fence. This is an on-chat command, instead of a function, so that it will run at the same time (asynchronously) as the rail is build. This speeds up the program. fence  can be run asynchronously without fear of interference with other functions because it changes no variables and uses no variables that might be changed elsewhere.

As shown in the drawing below, the four sides of the fence are built starting at the northwest corner and continuing in the following order:

  1. northwest corner to northeast corner
  2. northeast corner to southeast corner
  3. southeast corner to southwest corner
  4. southwest corner to northwest corner

drawing

The fill blocks in the graphic below are in this same order.

fence

Notice that in each fill block, the middle coordinate Y varies from 0 to 2, which makes the fence 3 blocks high.

Function to Lay the Rail with Redstone Under It

The function lay_redstone_and_rail is called by init_beginning. It sets the variables used by the function builder_square and calls it twice: once the lay redstone under the rail and once to lay the powered rail.

lay redstone and rail

Function to Build a Square with Missing Corners

The function bulder_square does build a square; however, the corner blocks are missing. The corners will be laid later because Minecraft requires that the straight sides be placed first so that it will know when to make a rail curve. I tried using  fill to lay the rail segments; however, this often laid the rails in parallel rather than connecting them. Frustrating.

build square

Function to Lay Rail Corners

The function lay_corner_blocks is called by init_beginning. This is a separate function so that it can also be called from a on-chat command corners. The on-chat command may be useful for repairing rails that have some square corners.

This function lays unpowered rail blocks because Minecraft will not turn powered rails into corners.  No matter — when using power, momentum carries the minecarts swiftly around corners, sometimes too swiftly with heavy MOBs (they fly right off the rail when trying to make the turn).

This function uses two four-item lists of position (see below)s:

  • rail_corners is the four positions of the rail corners, which will be the not-powered rail that should curve if all goes well.
  • rail_under_corners is the four positions underneath the rail corners, which will be the cobblestone foundation. I picked cobblestone just so that it would look different from the redstone, which  used everywhere else, to make clear that the corners are not powered.

By using these lists, a for_loop from 0 to 3 can be used to loop through the four corners.

lay corners

In the loop, the variable “where” is set to the corner position where the rail will be. The variable “under_where” is set to the corner position under the rail where the cobblestone will be.

The fill statement using air is employed to remove a undesirable square corner rail before placing another  in hopes that the new rail will curve. Through trial and error I found that the brief pause after replacing the old rail with air, then placing the new one makes corners works more often. But, unfortunately, not always.

Function to Set List of Rail Corner Positions

The two corners lists (below) are initialized by the function init_rail_corners_lists.

init_corners

The two empty items in the  rail_corners list are there so that the code will be vertical, not horizontal. The empty items have no effect on the size of the list or the code accessing the list. Empty items can also appear inside the list with no problems — empties seem to be ignored by MakeCode.

Control Buttons

The Spawn Position is the rail position east of the corner (left in this picture). When a minecart is placed on the rail, the next MOB in the spawn  list is spawned at the Spawn Position.

buttons for code

Four blocks are placed at the same level as the grass. I call these control buttons because when one of these is broken, it causes some action to take place. The broken block is replaced with either the same block or another block depending on the particular block.

Define Spawn Position and Place Control Blocks

The function shown below first defines the Spawn Position, then places the four control blocks. The Spawn Position is calculated as one block east of rail_corner, which was set in a previously defined function. The control blocks are set relative to the Spawn Position. Notice that, from SpawnPosition, the east/west  coordinate X  is incremented by 1 for each blocks will be side by side.  The Y coordinate is -1 so that the blocks will be level with the grass. The Z coordinate is the same for each block so that the blocks will be in a row.
place buttons

Code Requires a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_bPdMMvgg5Mjw

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.

Code Part 2 — on-Chat Commands for Riding the Rail in MakeCode for Minecraft

The Code that Processes on-chat Commands that Launch Riding the Rail

The code in the not-grayed-out area to the upper left in the screenshot below launches Riding the Rail. These chat commands define the MOBs to be spawned and the order in which they will be spawned.

code part 2

Goals for Riding the Rail included the following user-interface requirements:

  • For new players — a simple way to choose MOBs (animals and/or monsters) that will be available to ride in minecart and
  • For advanced players — the flexibility to choose any combination of MOBs.

The structure of the on-chat commands were the first step in accomplishing these goals. For new players there is an on-chat command for each MOB type; for example, when the program is launched with on-chat command “vindicator,” only vindicators will be available for riding the rail. Every time a MOB is placed on the rail, it will be a vindicator. Similarly, when started with “llama,” every MOB spawned will be a llama. For advanced players, the on-chat command “selected” will cause a player-modifiable function to be used to chose the MOBs thus enabling the ultimate in flexibility.

The on-chat commands that launch the program fall into the following two groups:

  • Commands that specify only one MOB type, for example, llama, pig or vindicator. These commands result in only the specified MOB type riding the rail .
  • Commands that specify more than one MOB type, for example, all  animals, all monsters, all animals and all monsters or a particular combination of specific animals and monsters (e.g., sheep and evoker).

Commands for Only One MOB Type

The simplest way to launch Riding the Rail is to type the name of a MOB in the chat window. The MOB name launches one of the code snippets in the picture below.

select by name

Each MOB name does the same thing except for setting the variable MOB_to_add to the chosen animal or monster. For example, the code below set MOB_to_add to the monster vex and calls the function run_one_MOB_type.
chat one mob type

The function run_one_MOB_type does the following:

  • sets the variable number_of_each_MOB_to_add to 1 (only 1 is needed because, with only 1 MOB type s in the list, it is spawned over and over again for as many as wanted.
  • calls the function init_beginning to move to a new position and build the field.
  • calls the function add_one_MOB_type_to_spawn_list, which does as it name implies.

Commands for More than One MOB type

The on-chat commands in the picture bellow can add more than one MOB type to the list of MOBs available to be spawned. These eight commands, are easier to remember interfaces to the “run” command (discussed next). These commands specify which MOBs to add to the spawn list and the order in which the are removed from the list, which can be either as ordered in the list or randomly selected from the list.

run

The above eight commands, call the run command with the appropriate two arguments:

  • num1 specifies the method used to add MOBs to the list of MOBs available to be spawned. num1 can have values 0 to 3, which correspond to (0) selected, (1) animals, (2) monsters and (3) both animals and monsters. The value of the num1 variable is saved in the variable mobs_to_spawn_list_creation_method to be used when the MOBs are actually added to the list.
  • num2 specifies the order in which the MOBs are to be spawned. The information in num2 is `stored in a Boolean value that is true if MOBs are to spawned randomly from the list or false if they are to be spawned in the order in which they are in the list. The text variable spawn_method is used only for say output.

run

Code Requires a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_bPdMMvgg5Mjw

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.

Code Part 1 — Overview of Riding the Rail in MakeCode for Minecraft

 

This post is a companion to Riding the Rail with MakeCode for Minecraft, which explains how to use Riding the Rail and  should be read first. This post is an overview of the code for Riding the Rails.

Code Goals

Goals for Riding the Rail included the following typical user-interface requirements:

  • For new players — a simple way to choose MOBs (animals and/or monsters) that will be available to ride in minecart and
  • For advanced players — the flexibility to choose any combination of MOBs.

As experienced coders know, to have both simplicity and flexibility in a user interface is difficult to achieve. After struggling with several approaches, Riding the Rail provides a reasonable solution to this problem.

A further goal was for the code to be able to place a MOB in a minecart rather than place MOBs and minecarts separately while hoping that some of the MOBs will jump into minecarts. Placing a MOB in a minecart proved troublesome; and, in fact, is the reason this program was not released months ago. The new on-item-used event enabled a tidy way to place MOBs in minecarts. Further, the ability to place MOBs and minecarts separately is retained because it can provide much amusement.

Another goal was for the code to build the powered rail without troubling a player with details. This goal was met except that, after the rail is built, on rare occasions, the corner rails are square, not rounded, as they should be. This is easily repaired by the player (see Riding the Rail with MakeCode for Minecraft), but it is a nuisance. While writing this, I was inspired to make yet another change to the rail-building code that I think may fix this problem. We’ll see.

Code Overview

The code for Riding the Rail consists of the following four logical parts:

  1. Part 2: on-chat Commands — The on-chat commands specify the MOBs that will be available to ride the rail.  The on-chat commands also specifies the order in which MOBs will be chosen for spawning (sequentially or randomly). The program remembers the source of MOBs and the order in which they are to be spawned, then moves on to build the field.
  2. Part 3: Building the Field — The code that builds the field on which Riding the Rail is played. The field consists of the following elements: the fence, the rail with the Spawn Position, the control buttons and a sunflower.
  3. Part 4: Spawn List — The code that initializes the “spawn list” using the information it saved earlier about the source of MOBs. The spawn list is the list of MOBs that will be available to ride the rail. The particular on-chat commnad that starts the program causes the variable mobs_to_spawn_list (the spawn list) to be filled with the chosen MOB or MOBs.
  4. Part 5: Event Processing — The code that processes the events that respond to player actions;  for example, right clicking on the Spawn Position to place a minecart with a MOB inside.

All the code for Riding the Rail is shown below.

code all

The post describing this code grew so long that it became nigh impossible to work on. Therefore, I have split the description into four posts, each with its own video, explaining a section of code. The four posts are as follows:

Code Part 2: on-Chat Commands for Riding the Rail in MakeCode for Minecraft

The code described in Part 2  processes on-chat commands that launch Riding the Rail. These chat commands define the MOBs to be spawned and the order in which they will be spawned. The code is the not-grayed-out code to the upper  left in the screenshot below.

code part 2

Code Part 3: Build the Field for Riding the Rail in MakeCode for Minecraft

The code described in Part 3 builds the field (e.g., fence, rail and control buttons). It is the not-grayed out routines near the middle of the screenshot.

code part 3

Code Part 4: Spawn List for Riding the Rail in MakeCode for Minecraft

The code described in Part 4 initializes the spawn list with the MOBs specified by the on-chat command that started the program. The code is the not-grayed-out areas (to bottom left and middle).

code part 4

Code Part 5: Event Processing for Riding the Rail in MakeCode for Minecraft

The code described in Part 5  processes events in response to player actions. It is the not-grayed-out areas in the screenshot below.

code part 5

Code Requires a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_bPdMMvgg5Mjw

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.

Riding the Rail with MakeCode for Minecraft

 

Riding the Rail Cam 2 smaller

Dedication

This code is dedicated to the new MakeCode for Minecraft block

on item placed

without which Riding the Rails would not be nearly so awesome. Shout-out to The MakeCode Team for this and all the other marvelous new features. I built the first version of this program several months ago. I didn’t release it because I could not figure out how to spawn a MOB (animal or monster) inside  a minecart — until the on-item-used block.

With the new on-item-used block, a MOB can  easily be spawned in a minecart by placing the  minecart  at a know spawn position. The code below shows how. With a minecart selected in the Hotbar, the player right clicks the Spawn Position (left picture) to place a minecart. This triggers the on-minecart-used event and the MOB is spawned in the cart. Yippee!

The pictures below show several results of placing a minecart at the Spawn Position.

Using Riding the Rail

Riding the Rail builds a powered rail inside a fence. The player uses the control buttons to add minecarts and MOBs. The fence prevents mobs that can be contained from leaving the fenced area. Some MOBs will jump into a minecart. Or, the player may chose to have them spawned in the cart. Some MOBs will crowd into a cart even if it already occupied. Heavy MOBs sometimes wreck as they go around a rail corner. I haven’t found an end to the fun and experiments.

Below is the field on which Riding the Rail is played. Inside a square 3-block-high fence is a square powered rail with the needed redstone under it. The corners of the rail are not powered, which is a Minecraft requirement. The sunflower in the bottom left corner is, as always, facing east. Knowing one’s direction is essential when exploring the code.

field 3

The circled rail segment shown below is a special position called the “Spawn Position.” The Spawn Position is used to spawn MOBs in minecarts.

spawn position 2

To Place a Minecart with a MOB in It

Right clicking the Spawn Position will cause a MOB to be spawned in a minecart if the following two conditions are met:

  1. In the Hotbar, the minecart is selected (see picture above). Set it to one by touching it or typing 1 on the keyboard with chat windows closed.
  2. The control block nearest the corner  is gray, not black. Left clicking the gray  block (breaking it) will cause it to turn gray. If black, clicking will turn it gray.

To Place a Minecart by Itself and Spawn a MOB at the Spawn Position

If the above two condition are met, right clicking anywhere on the rail other than the Spawn Position will place a minecart at the rail position and spawn a MOB at the Spawn Position.

Using a Touch Interface (iPad and Windows 10 Touch)

At this time, on a touch -interface (e.g., iPad, touch Windows 10), to place a minecart with a MOB in it, requires as extra step.

  1. First, tap  (right-click equivalent) the Spawn Position to place the minecart.
  2. Then, tap and hold (left-click equivalent) the brown button to cause MOB to be spawned in the minecart.

This two-step process is required the on-item-used event is not operating as expected when using a touch interface. This is  described in my post Weirdness in the On-Item-Used Event with Touch-Interface MakeCode for Minecraft

To Place a Minecart by Itself — No MOB

If the gray/black button is black, right clicking anywhere on the rail will pace a minecart at the clicked position. No MOB will be spawned. The gray/black button is the one nearest the corner. If the button is gray, turn it black by left clicking to destroy it. It will be replaced by a black button. Click again to turn back to gray.

To Spawn a MOB by Itself — No Minecart

Left clicking the green button will cause a MOB to be spawned at a random location inside the rail square. This is useful when exploring which MOBs will jump into minecarts (most will eventually).

Specifying Mobs to be Spawned

The simplest way to specify which MOBs will be spawned, is the start the program by typing the name of a MOB in the chat window.

select by name

For example, if the program is started by typing “llama” in the chat window, every MOB spawned will be a llama.

llamas

If the program is started by typing “spider” in the chat window, every MOB spawned will be a spider.

spiders

If the program is started by typing “shulker” in the chat windows, every MOB spawned will be a shulker. As of this writing, only three monsters can be spawned in Minecraft Education Edition: shulker, vindicator, and evoker; but, all are available in MakeCode for Minecraft on Windows 10.

shulkers

If more than one type of MOB is desired, one of the following commands can be typed in the chat window:

  • selected — this is the most advanced method of selecting MOBs to be spawned and will be described in the section Advanced MOB Selection. The MOBs selected will be spawned in the order they were specified.
  • animals — all animals in the animalList will be available to be spawned in the order they are in the list.
  • monsters — all monsters in the monsterList will be available to be  spawned in the order they are in the list.
  • all — all animals in animalList and monsterList will be available to be spawned, with animals first.
  • selected_random — same as “selected” except that specified MOBs are spawned in random order and may be repeated.
  • animals_random — same as “animals” above except that specified MOBs are spawned in random order and may be repeated.
  • monsters_random — same as “monsters” above except that specified MOBs are spawned in random order and may be repeated.
  • all_random — same as “all” above except that specified MOBs are spawned in random order and may be repeated.

run

The command above such as “animals” are simply more memorable ways of using the “run” command with number arguments specifying the MOB source and the order in which they are to be spawned. Of course, one can use the run command with the appropriate arguments. “run” with no arguments, which means that both arguments are zero, is the same as using “selected.”

In the picture below,  the program was started with the command “animals” spawning the animals in the order in which they are in animalList (see next section).

animals

Similarly, the command “monsters_random” enables spawning the monsters chosen randomly from monsterList. For each spawn a monster is selected randomly from the entire monsterList; therefore, the same type of monster may be spawned multiple times.

monsters 5

The on-chat command “selected and “selected_random” cause the MOBs to be selected by the function “specify_mobs_to_spawn,” which can be modified by the player. It enables the player to have complete control over which MOBs and how many of each are to be spawned.  the function is described in the following section. The picture below shows the result of using the function to create the spawn list as 5 chickens and 1 ocelot. This was an experiment was to see if the ocelots would kill  the chickens.  After spawning 20 MOBs, 17 were chickens and 3 were ocelots.

ocelots and chickens

After a few minutes, the situation was as shown below: the ocelots had killed the chickens in the minecarts next to them. Then, one ocelot  jumped out to get the chicken in the middle.

ocelots and chickens eaten

Wonder what the situation would be later?

MakeCode Lists Specify the Available MOBs

Available MOBs are specified in  animalList and monsterList as shown below.  The player can change the lists as desired. All possible MOBs that make sense to spawn in a minecart are included here. MOBs not included are those — like fish and bats — that either will not survive or just will not stay inside a cart. A player might want to rearrange the order of MOBs in a list or even remove some MOBs. Since as of this writing, only the first three monsters work in Minecraft Education Edition, the player should remove all others.

mobs

Advanced MOB Selection

As an option, the player can further specify the MOBs to be used by changing the function below. This function is only used if either of the commands “selected” or “selected_random” start the program.  This function  puts the MOBs to be used in a list called mobs_to_spawn_list. The four sections of this function have blocks that can be changed as follows:

  1. Specify the stop_MOB_index_p1 (“p1” means plus one) for the animalList. Also specify the number of each of the selected animals to be spawned. This number can be 0,  in which case no animals will be included.
  2. Specify the stop_MOB_index_p1 for the monsterList.
  3. Set MOB_to_add to be a specific animal and specify the number of animals of this type to be spawned, usually 1.
  4. Set MOB_to_add to be a specific monster and specify the number of monsters of this type to be spawned, usually 1.
  5. The last to section can be duplicated if multiple animals and/or monsters are desired, which is what I did to get the chickens and ocelots in the proportions I wanted in the experiment described above.

specify mobs

Stopping and Starting Minecarts

Using a left click to break the circled sandstone block (left picture), will cause the redstone blocks under the rail to be replaced by sandstone (right picture). This removes all power from the rails and causes the carts to slow and stop except for those with enough momentum to continue for a time.  Breaking the circled redstone block (right picture) will replace all sandstone with redstone restoring power to the rails and start the carts moving again.

on-chat command “corners”

Sometimes some of the four rails corners may not be round. This is a Minecraft issue beyond my control  If have thought that it might be a timing issue: the program runs much faster than a player can “manually” lay track. I have experimented with pauses before laying corners to no avail. An on-chat command “corners” is supplied to correct the corners that are not round; however, often once a corner has decided to be square likely running corners again will not correct it. Usually using another chat command, like “animals,” will  generate proper corners. Stopping and starting the program does not help.

A way to fix the square corners that always works is to  employ the following steps:

  1. Destroy the wrong corner by left clicking it.
  2. Right click the same place with the unpowered rail selected in the Hotbar.

I have noticed that if there is one square corner, there is likely another. Flying above the rail to verify that all corners are correct before starting to spawn MOBs is good practice — or one can just wait until some carts with their occupants pile up at the square corner. That’s fun, too.

on-chat command “moveme”

The command moves the player 200 blocks east, which is likely a clear area of the world. It is not necessary to use this command because when the program starts, it will do it.  I use “moveme” when the MOB sounds  get annoying.

To Jump into a Minecart Yourself

A player might want to ride the rail herself. To do so follow these two steps:

    1. Place a minecart on the rail in.
    2. Right click inside the minecart.
  • To get out out of the cart, jump or fly out.

 

The Code

The code  will be described in my next post. To whet your appetite, the picture below displays all the code for Riding the Rail.

all code

Get the Code

Riding the Rail code is shared on Code Connection at this URL

https://makecode.com/_gRugtXMFRam2

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.

Weirdness in the On-Item-Used Event with Touch-Interface MakeCode for Minecraft

Having finished my next major program, Riding the Rails , I was testing it on various platforms to note any incompatibilities. One incompatibility I knew about — that Education Edition only has three of the 24 monsters in Minecraft on Windows 10. This is not a big problem as long as a player knows what to expect.

However, while testing on the iPad, I found a much more serious problem. The on-item-used event, new in the latest release, does not work the same way on the iPad as it does on the Minecraft Education Edition. After experimenting with workarounds and testing, I came to understand that the actual incompatibility was between keyboard-mouse-interface usage and touch-interface usage. To wit, using only the touch interface on Microsoft Surface Studio demonstrated the same anomalous behavior as on the iPad. When using the keyboard-mouse interface on the same Surface, there was no incompatibility.

Results on-item-used Compatibility Tests

Summary

The table below show test results for both keyboard-mouse interface and touch interface for each of  three systems: MakeCode for Minecraft on Windows 10, MakeCode for Minecraft Education Edition (Windows 10) and MakeCode for Minecraft Education Edition (iPad). As expected results are shown in blue. Not as expected results are shown in red. Blue good. Red bad.

event behavior

Further information on these test results are demonstrated in the sections below.

Microsoft Surface Studio Keyboard-Mouse Interface Compared to Weird Touch Interface

To demonstrate this discrepancy, I used Minecraft Education Edition on a Surface Studio.  I will first show a short video of keyboard-mouse usage of the on-item-used event then I will show a touch-only usage on the same system.

The keyboard-mouse interface on MakeCode for Minecraft on Windows 10 works as expected — like the keyboard-mouse interface on Education Edition.

iPad (Touch Interface) on-item-used Event Weirdness

Now I’ll run the same program on the iPad.

Test on MakeCode for Minecraft on Windows 10

The test on MakeCode for Minecraft on Windows 10 yielded the same results as the Education Edition: using keyboard-mouse interface the on-item-used event worked as expected; but, using touch interface it did not.

The Code

This code is designed only for exploring the awesome new on-item-used event in MakeCode for Minecraft. The code has two parts. First, the on-start block, which runs every time the program starts, and second, the event code for each type of  item used, which runs for the appropriate on-item-used event.

On-start

The on-start block gives the player five items that will be used to generate on-item-used events.

on start

There are five on-item-used event blocks, each with code specific to the item used. Each of these blocks increments a counter for the specific item and says the item name along with the count.

on item used

Get the Code

on-item-used Weirdness  code is shared on Code Connection at this URL

https://makecode.com/_aJ01ejCbT7Yc

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.

Happy Day! MakeCode for Minecraft on Windows 10 Is Back!

No doubt about it. I’ve tested on 3 computers: Code Connection maintains a connection. MakeCode for Minecraft on Windows 10 is working perfectly.

I ran the test program from yesterday’s post Missing Monsters in MakeCode for Minecraft Education Edition and, sure enough, all monsters are present in MakeCode for Minecraft on Windows 10.

Get the Code

Monsters code is shared on Code Connection at this URL

https://makecode.com/_0MAW16htVifj

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.

Missing Monsters in MakeCode for Minecraft Education Edition

 

This program, which we’ll dub “Missing Monsters,” is designed to test that monsters spawn as they should in MakeCode for Minecraft Education Edition. As of this writing, only Shulker, Vindicator and Evoker spawn correctly. When trying to spawn a ghost, something pink appears briefly; however, no ghost is spawned. All the other monsters simply do not spawn. When the post Monster Showtime in MakeCode for Minecraft was published, all monsters spawned as expected in MakeCode for Minecraft on Windows 10.

Using the Missing Monsters Program

Missing Monsters offers the following 3 on-chat commands:

  • run
  • go
  • ghosts

Run

The run command is used first. It will cause “ready to go” to be printed in the sky. The player should face so that “ready to go” can be seen.

Go

The go command is used after the player is positioned  so that the sky printing is visible. After the go command, the player need not be moved — hands off.  Each monster will be separately spawned with its name written in the sky. To allow for viewing time, there is a brief wait after each monster. Each monster’s name will be printed in the sky. If the monster is spawned correctly, it will appear a few blocks in front of the player. Be patient — the correct ones are at the end of the monster list. Vex is the last monster.

Ghosts

The ghosts command can be used after go has completed. This command will generate 10 ghosts, one at a time, with a brief wait after each one.

Ghosts

The pink thing above flashes on the screen when a ghost should be spawning. But, if you blink, you will not see it. I captured this figure by clipping a frame from a video. This thing looks kind of like a ghost, but pink? Really? And, ghosts may float away, but, as far as I know, they don’t flash briefly and disappear.

The Code

The code is show below. It is a simplification of the code in  Monster Showtime in MakeCode for Minecraft.

code all

The Code Assumes a Flat World

This code assumes a flat world such as that described in MakeCode for Minecraft Sandbox World: Make It Flat and Simple.

Get the Code

Missing Monster  code is shared on Code Connection at this URL

https://makecode.com/_YLiKDc5E0HrY

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.