Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Tutorial 3.1. Remote processes

Adrodoc edited this page Jun 1, 2018 · 18 revisions

Each remote process relates to a command chain in Minecraft. Therefor a remote process can either be impulse or repeat. The special thing about remote processes in contrast to the simple programs we had before is that they can be called remotely both by the player and by other command blocks.

The following program defines 2 remote processes which can calculate 5 to the power of 3

install {
  /scoreboard objectives add POW dummy
  /scoreboard objectives setdisplay sidebar POW
}

uninstall {
  /scoreboard objectives remove POW
}

impulse process testPow {
  /scoreboard players set base POW 5
  /scoreboard players set exponent POW 3
  /scoreboard players set result POW 1
  start pow
}

repeat process pow {
  /scoreboard players operation result POW *= base POW
  /scoreboard players remove exponent POW 1
  // This should test for 0 0 once this bug is fixed: https://bugs.mojang.com/browse/MC-97060
  /scoreboard players test exponent POW * 1
  conditional: stop
}

Once we install the program we can start the process testPow by executing the following command:

/execute @e[name=testPow] ~ ~ ~ setblock ~ ~ ~ redstone_block

In the sidebar you should now be able to see the correct result of 125.

You can also manually play around with the scoreboard values and call the process pow to calculate different results. To call the process pow use this command:

/execute @e[name=pow] ~ ~ ~ setblock ~ ~ ~ redstone_block.

Starting and stopping

To start a process in a program you can use the keyword start with the name of the process. You can do this in another process or in the installation / uninstallation:

install {
  start myProcess
}

impulse process myProcess {
  /say Hi my name is myProcess
}

This works the same way with repeat processes.

A remote process can also be started by a player. If you compile your program with the compiler option transmitter you can place a redstone block at the process as we have seen above:

/execute @e[name=myProcess] ~ ~ ~ setblock ~ ~ ~ redstone_block

If you are not using that compiler option you need to set the first command block to be always active:

/execute @e[name=myProcess] ~ ~ ~ blockdata ~ ~ ~ {auto:1}

When you start an impulse process its contents are executed and then the process terminates. A repeat process behaves a bit differently. It acts like an infinite while loop, so it does not stop on its own. To stop a repeat process you have to use the keyword stop with the name of the process. If you want to stop the repeat process you are currently in you can omit the process name:

install {
  start myProcess
}

repeat process myProcess {
  /say Hi my name is myProcess
  stop
}

Due to MC-97060 the contents of a repeat process are executed once more after stopping the process. Because of that the say command of the last example is executed twice.

Both start and stop can have a conditional modifier:

install {
  /say A say command is always successful
  conditional: start started
  invert: start notStarted
}

impulse process started {
  /say I am started
}

impulse process notStarted {
  /say I am not started
}

Timing

When you start another process it does not start that process immediately. Instead the other process is started 1 game tick later. To illustrate this you can try out the following program:

install {
  start main
}

impulse process main {
  /say starting program
  start other
  /say I am the main process
}

impulse process other {
  /say I am the other process
}

You should see the following output:

starting program
I am the main process
I am the other process

This is because the process "main" finished execution in the first game tick and then in the second game tick the other process is started. If you want to wait for another process, for instance because you want to use a result of a calculation you can call the process instead:

install {
  start main
}

impulse process main {
  /say starting program
  other()
  /say I am the main process
}

impulse process other {
  /say I am the other process
}

Now the output should look like this:

starting program
I am the other process
I am the main process

Do you notice how the two lines in the output are swapped? This program now takes 3 game ticks to run:

  1. The main process is started and then stops itself to wait for the other process
  2. Now the other process is started, finishes and tells the main process to continue with execution
  3. The main process continues and the whole program comes to an end

In Tutorial 3.3. Events we will take a closer look at how this works, but first you should learn about inline processes in Tutorial 3.2 which can be a great alternative to remote processes.

Clone this wiki locally