<- Go back

Rover Coder Documentation

This is the documentation of all the available properties and functions for Rover Coder.

Golden Rules

  1. Use your web browser's developer console
  2. Learn by trying, and failing
  3. Plan out your solutions before coding

Programming a Rover

All Rover programs are TypeScript functions that have the following format.

({
        start: (rover) => {
            // Start code goes here
        },
        
        update: (rover) => {
            // Update code goes here
        }
})

The start function will be where the bulk of your code will live. Think of this as your rover's "main" function that runs as soon as you upload the code.

The update function will run every game tick (i.e. every frame). This is useful for more advanced features.

Rover Properties

Your rover has a variety of different properties that you can access to make decisions. Here is a list of all the accessible properties

Memory

You can access the map data from your rover's area scans from lastScan. You can also have your own variables in this dictionary to help keep track of anything your rover may need. You can read and modify this variable.

TypeScript Definition

memory: {
        lastScan?: { x: number, y: number, data: TileData | null }[][],
        [varName: string]: any
    }

Inventory

A dictionary of the amounts of world objects the rover is carrying. You can read this variable, but you cannot modify it.

TypeScript Definition

inventory: {
        [WorldObject.Rock]: 0, // Rock
        [WorldObject.Plank]: 0 // Plank
    }

Health

The number of hearts the rover has left. You can read this variable, but you cannot modify it.

TypeScript Definition

health: number

Rover Actions

Along with rover properties, you can also call a series of different functions to change how the rover behaves. When an action is called from the rover program, it will add this action to the queue of actions. Rovers will perform actions one at a time in order of when they recieved them.

moveToFlag(label: string) - The rover will attempt to move to the flag of the label argument. If there is no path, this will fail. The label parameter accepts capital letters A through Z.

moveTo(x: number, y: number) - The rover will attempt to move to the specific coordinate position of (x, y). If there is no path, it will fail.

moveForward(steps: number) - The rover will attempt to move forward a certain number of tiles, specified by steps.

repair() - The rover will repair itself at a rate of 1 heart per second.

faceDirection(dir: 'north' | 'east' | 'south' | 'west') - The rover will spin to face one of the specified cardinal directions.

wait(ms: number) - The rover will stop and wait for a specified number of milliseconds. (1000ms = 1 second)

scanArea(radius: number) - The rover will scan the area and store tile data in memory. The larger radius of scanning, the longer the scanning will take. For each increment of radius, scanning takes an extra second. The max scan radius is 10 tiles.

breakObject() - Breaks the current object directly in front of the rover and adds it to the rover's inventory. The currently 'selected' tile is highlighted by a white box on the game screen. If there is no breakable object, this will fail. It takes 3 seconds to break an object.

placeObject(object: WorldObject) - Places an object from the rover's inventory onto the selected ground in front of the rover. If there is already an object in that tile or if the rover does not have the object in its inventory, this will fail. It takes 1 second to place an object.

attack() - The rover will do a spin attack, hitting all monsters in a one tile radius from itself.

Action Interventions

These functions help manage the current action and queue of actions of the rover. This is useful in situations where there is a more pressing matter than the current actions such as a monster attack. In the case of a monster attack, the rover should stop what it is doing, and fight back.

stopCurrentAction() - Stops whatever the rover is currently doing.

clearActionQueue() - Clears all actions that are queued up by the rover. This does not trigger the idle event.

Rover Events

Events help manage rover's actions based on whatever happens in the game world. Whenever an event is triggered, the user's callback function is ran.

Available Events

Example

This example creates an event that aborts its current action when it is damaged, unless that current action is its attack action.

({
    start: (rover) => {
        rover.on("damage", () => {
            if(rover.currentAction?.type !== 'attack'){
                rover.stopCurrentAction();
            }
            rover.attack();
            rover.repair();
        });
    },
                        
    update: () => {

    }
})

Misc.

Here are some useful enumerations

export enum Tile {
    Grass = 0,
    Stone = 1,
    Water = 2,
}

export enum WorldObject {
    Rock = 0,
    Tree = 1,
    Plank = 2,
}