Skip to content

API Reference

JoeStrout edited this page Jan 26, 2022 · 17 revisions

The functions and classes added to the MiniScript core are called Application Programming Interfaces, or APIs. These are the built-in functions and methods you can use in your own Farmtronics programs.

Global Methods

Function Usage
bot Module of bot-related methods (bots only; null on the Home Computer)
env Environment options; see https://miniscript.org/wiki/Env
exit Exit the current script, returning to the command line
farm Reference to the Location that represents your farm
file File-handling module; see https://miniscript.org/wiki/File
import libname Import a library module; see https://miniscript.org/wiki/Import
input(prompt) Get a string of input from the user (https://miniscript.org/wiki/Input)
key Module related to keyboard input; see https://miniscript.org/wiki/Key
text Reference to the TextDisplay

Location Class

The Location class represents one area of the map. Each time you walk off the edge of the map (or through a door), the screen briefly goes dark, and then you appear in another part of the map, you have changed to a different location. Your farm is a Location, accessible via the global reference farm. You can also get a bot's location using bot.here (or bot.position.area).

Once you have a reference to a Location, you may use the following properties and methods.

Property/Method Meaning
width number of columns of tiles
height number of rows of tiles
tile(column, row) a map of information about the given tile, or null

The tile information will be null for empty, unimproved ground. For anything else you will get at least:

Key Value Type Value
type string base feature type

For trees, you will also get:

Key Value Type Value
treeType integer type of tree
growthStage integer tree's current stage of growth
health integer tree health
stump boolean whether this tree has been cut down
tapped boolean whether this tree has been tapped
hasSeed boolean whether this tree has seeds available

When the base type is "HoeDirt", then you will get:

Key Value Type Value
dry boolean whether this dirt is dry (true) or watered (false)
crop map map of information about the crop growing here, or null if none

The crop information provided is:

Key Value Type Value
name string name of the crop being grown, e.g. "Potato"
phase integer current growth phase of this crop
maxPhase integer number of growth phases of this crop type
mature boolean whether crop is fully grown (Note 1)
dead boolean whether the crop is dead
harvestable boolean whether this crop is ready to harvest
harvestMethod integer 0 = normal (hand), 1 = scythe

Example: this script, on a bot, will print information about the crop ahead of it.

if not bot.ahead then
  print "Nothing ahead."
else if not bot.ahead.crop then
  print "I see " + bot.ahead.type + " ahead, but no crop."
else
  print "Growing: " + bot.ahead.crop.name
  print "Growth phase: " + bot.ahead.crop.phase + "/" + bot.ahead.crop.maxPhase
  if bot.ahead.crop.harvestable then
    print "Ready to harvest with method " + bot.ahead.crop.harvestMethod
  end if
end if

Bot Module

Clone this wiki locally