Skip to content

Standard Modules

Alan edited this page Apr 8, 2025 · 12 revisions

Standard modules are modules available to all the bots by default. These modules either allow you to control bots' movement, manage their inventories, connect to other bots, or access some language features like instantiating arrays and dicts.

Lang Module

Language module is a standard module that contains functions for creating arrays, dicts, parsing numbers, converting objects to strings, etc. Importing this module is not necessary as it's functions are imported by default. You can access them simply by invoking them. However, if the import is necessary (if you have conflicting function names), you can import this module with import lang. Language module has the following functions:

// Returns a new array with the size of "capacity"
// Capacity is an optional parameter, and by default it's 8 (configurable)
array(capacity)

// Returns a new dictionary object
dict()

// Returns a length of a text, size of an array, or size of a dictionary
// input must be of type string, array or dict
length(input)

// Puts a key-value pair into the specified dict
// This function is just an alternative to: dict[key] = value, which you are more likely to use
dict_set(dict, key, value)

// Removes an entry from the specified dict with a specified key
dict_unset(dict, key)

// Convert some data into a string
to_string(data)

// Attempt to convert string into an integer
// Example: to_int("5")
to_int(input)

// Attempt to convert string into a decimal number
// Example: to_float("0.3")
to_float(input)

// Pauses the bot for the specified duration
// duration uses bot ticks as a unit of time, 1 tick equals to 0.1 seconds, 10 ticks are exactly 1 second
sleep(duration)

Bot Module

Bot module is a standard module and one that you will use the most often. You can import it using import bot, and it has the following functions:

// Prints the message in the chat
chat(message) // message must be a string

// Displays the message above the bot for "duration" (in seconds) amount of time
setStatus(message, duration [optional]) // Duration is optional, it's 5 seconds by default

// Move the bot in the specified direction
move(direction) // direction can be: "up", "down", "forward", "back", "north", "east", "south", "west"

// Rotate the bot counter-clockwise
rotateLeft()

// Rotate the bot clockwise
rotateRight()

// Get the direction the bot is facing
getDirection() // returns "north", "east", "south" or "west"

// Returns a type of the block in the direction relative to the bot
// For example, getBlock("down") will return "pumpkin" if the bot is above a pumpkin
getBlock(direction)

// Mine a block in the specified direction
mine(direction)

// Get selected slot number in the bot's inventory
getSelectedSlot()

// Select a slot in the bot's inventory
// - specified slot must be a number between 0 and 6 (inclusive)
setSelectedSlot(slot)

// Returns a name of an item in the specified slot
// - specified slot must be a number between 0 and 6 (inclusive)
getItemInSlot(slot)

// Returns a name of an item in the bot's selected slot
getSelectedItem() // i.e: "pumpkin"

Monitor Module

Monitor module is a standard module and it's used for controlling monitors. It has the following functions:

// Connects to the monitor. Bot must connect to a monitor before using its functions!
connect(monitor_id) // monitor_id is displayed on monitors

// Prints the message on the monitor
print(message) // message must be a string

// Prints the message on the monitor, and adds a new line
println(message) // message 

// Returns the hex value of the current text color
getTextColor()

// Sets the color of text. Color is only applied to text that comes after setting it.
setTextColor(color) // color is a string representing a color (i.e: "black", "#f0f0f0")

// Sets the color of text. Color is only applied to text that comes after setting it.
setTextColorRGB(red, green, blue) // red, green and blue are numbers (0-255)

Clone this wiki locally