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.

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

  1. Pingback: Code Part 1 — Overview of Riding the Rail in MakeCode for Minecraft | We Code MakeCode

  2. Pingback: Code Part 4 — Spawn List for Riding the Rail in MakeCode for Minecraft | We Code MakeCode

Comments are closed.