Skip to content

Standard Modules

alantr7 edited this page May 14, 2024 · 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:

// 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"

Clone this wiki locally