Skip to content
Yan Soares Couto edited this page Mar 13, 2017 · 4 revisions

Intro

This page should be a (more or less) comprehensive list of all instructions in Marvellous Inc. terminal, their parameters, behaviors, etc. First let's talk about a line of code and recurring parameters in instructions.

A line of code

In the terminal, at most one instruction is allowed per line. The general structure of a line is

label_id instruction comment

Where label_id is an alphanumeric string followed by a colon :, instruction is one of the instructions discussed below, with its parameters, and comment is any string preceded by a hashtag #.

The terminal only allows alphanumeric characters, plus any of the characters [] #:+-. Extra whitespace does not matter to the interpreter.

Common parameters

First let's define a number and a string.

A number is a number from -999 to 999, possibly surrounded by brackets, 5 means 5, while [5] means what is stored in register #5 (when the number is being evaluated), [[5]] means what is stored in the register pointed by register #5, and so on.

A string is just a sequence of characters.

There are four common types of parameters used in the commands: value, address, label and direction. For example the walk command may be given by walk value direction.

  • value is just a number
  • address is a number that specifies the number of a register
  • label is a string that is the same as an existing label_id, or a number that, when evaluated, is an existing label_id. That means [5] is a valid label, but not a valid label_id, for example.
  • direction is a string that is either up, down, left, right, north, south, east or west. Both up and north have the same effect, and so on.

Note

The terminal will try to detect all "compile-time" errors, that means errors that will always happen when executing a line, like accessing invalid register positions and such. Some however, cannot be detected and may fail while running, for example if address is [0], and during runtime register #0 has value -1, the execution will fail.

In the instructions below, unless otherwise stated, whenever a value given in runtime is unexpected, you will get a Runtime Error and your code will stop executing.

List of instructions

  1. walk
  2. walkc
  3. turn
  4. jmp
  5. pickup, drop
  6. add, sub
  7. mov
  8. read, write
  9. jgt, jge, jlt, jle, jeq, jne

==========================

walk value direction

The bot turns to direction and then the walks value steps. One or both of the parameters may be omitted. If value is omitted, the bot will walk until it finds an obstacle. If direction is omitted, then the bot will walk in the direction it is facing.

value must be greater than or equal 0. If it is equal to 0 the robot will turn (if a direction is given), but won't walk.

Examples

walk 3 down # Walks 3 positions down
walk east # Walks right until it hits an obstacle

Note

In this command the order of the parameters may be switched, but in most other commands this won't work.

==========================

walkc address direction

The bot turns to direction, walks until it finds an obstacle and then stores the number of steps walked in the register given by address. The argument direction is optional, and if omitted the bot will keep facing the same direction.

Examples

walkc 0 up
pickup up
walk [0] down

With this code the bot will walk north until finding an obstacle, pick it up, and then return to the same position.

==========================

turn direction

The bot will turn to direction. In this command, direction may assume two extra values: clock and counter, if one of these are given, the bot will turn clockwise or counterclockwise, respectively.

Examples

turn clock
turn clock

This code will turn the robot to the oposite direnction it is facing

==========================

jmp label

The next code line executed will be the line labeled with label_id equal to label, instead of going to the next line. If label is a number, it will be evaluated first, that means jmp [5] will jump to the label that is the same as the number written in register #5.

Examples

lp: turn counter
walk 1
jmp lp

This code will make the bot walk endlessly in a 2x2 square, in counterclockwise direction.

mov 5 0
jmp [0]

This code will jump to label 5, but if register #0 had a different value it would change to a different label.

# Advanced Example
func: walkc 1
turn clock
turn clock
walk [1]
turn clock
turn clock
jmp [0]
...
...
mov 111 0
jmp func
111: # continue

In this example, jumping to func will store in the register #1 the number of steps you can walk forward until hitting something, using the register #0 as a "return position". Jumping to this label may be seen as a simple function, since it can be called from anywhere and will return to where it was called.

==========================

pickup direction

The bot will first turn to direction, and then pickup the object on the tile it is facing. The argument direction is optional, and if omitted the bot will keep facing the same direction.

If the bot tries to pick up an invalid object or its inventory is already full, you will get a Runtime Error.

Note

It is possible to pick up paint from a paint container by having an empty bucket on your inventory and using pickup on the paint container.

drop direction

Analogous to pickup, but the bot will drop the object it is currently holding in the given direction, or in front of it if no direction is given.

If the bot tries to drop the object in an invalid position or its inventory is empty, you will get a Runtime Error.

Examples

pickup up
walk 1 down
drop

This code will pickup an object from the north and drop it 3 blocks down from where it was.

Note

Dropping a bucket with water will also drop the bucket. Dropping a bucket with paint will only paint the tile in the chosen direction, and keep an empty bucket on your inventory.

==========================

add value1 value2 address

The sum of value1 and value2 will be stored in the register with number address.

sub value1 value2 address

The same as add, but for subtraction.

Examples

add [0] 1 0 # Increments the value in register #0 by 1
sub [7] [3] 1 # Stores in register #1 the value in register #7 subtracted by the value in register #3
sub 0 [5] 5 # Negates the value of register #5
add [1] [1] 1 # Doubles the value of register #1

==========================

mov value address

Stores value in the register given by address. Notice that this is just a fancy version of add value 0 address.

Examples

mov [0] 1
mov [0] 2 # Copies the value of register #0 to registers #1 and #2

==========================

read address direction

The bot turns to direction and then reads one number from the console1 it is facing, and stores it in the register given by address. The direction argument is optional, and if omitted the bot will read from the console in front of it.

Reading a number removes it from the console. If there are no more numbers on the console, you will get a Runtime Error.

1 Consoles are the big colorful computer objects in the room.

write value direction

The bot turns to direction and then writes value to the console it is facing. The direction argument is optional, and if omitted the bot will write to the console in front of it.

Notice that it is different than read because it receives a value and not an address. That means reading from console to register #0 uses the command read 0, and writing to the console from the same register uses the command write [0]. Be careful.

If the the number is invalid (depends on the puzzle), you will get a Runtime Error.

Examples

write 12 right
write [12] left

This code writes 12 to the console on the right, then the content in register #12 to the console on the left.

label: read 1 left
add [1] [1] 1
write [1] right
jmp label

This code reads values from the console on the left, and writes them, doubled, to the console on the right.

==========================

jgt value1 value2 label

If value1 is greater than value2, then the next line executed will be the one with label_id equal to label. That is, if value1 is greater than value2, this instruction will be the same as jmp label, otherwise, it will do nothing. Everything said about jmp also applies here.

The other commands work exactly like this, except the condition to jump is different. Here is the list of all conditional jumps:

  • jgt - jumps if value1 > value2, that is, if value1 is greater than value2
  • jge - jumps if value1value2, that is, if value1 is greater than or equal value2
  • jlt - jumps if value1 < value2, that is, if value1 is less than value2
  • jle - jumps if value1value2, that is, if value1 is less than or equal value2
  • jeq - jumps if value1 = value2, that is, if value1 is equal value2
  • jne - jumps if value1value2, that is, if value1 is not equal value2

Examples

mov 10 [0]
666: write 1 left
sub [0] 1 0
jne [0] 0 666

This code writes 1 to the console on the left exactly 10 times. This is what you could call a for loop.