-
Notifications
You must be signed in to change notification settings - Fork 18
Bot Code Examples
You can extend the me
module by simply assigning new functions to it. If you do this in /usr/startup.ms
, then they will automatically be loaded when any bot (or the Home Computer) is booted up.
This adds a .till
method that selects the Hoe and applies it to the tile in front of the bot. (Of course the bot must actually have a Hoe in its inventory for this to work.)
me.till = function
me.select "Hoe"
me.useTool
end function
Similar to the above example, but instead uses the watering can to water whatever is in front of the bot.
me.water = function
me.select "Watering Can"
me.useTool
end function
This example selects a seed packet by name. Again, the bot must of course have such a seed packet. You would call this, for example, as me.plant "Parsnip"
me.plant = function(seedName)
me.select seedName
me.placeItem
end function
Here's a more complex example that takes two parameters, the width and height of an area to clear, and then moves the bot back and forth, clearing that area. This involves two right turns at the end of the even rows, and two left turns at the of the odd rows, in order to keep the bot advancing down the rows.
me.clearGrid = function(width, height)
for h in range(0, height-1)
me.clearAndMove width
if h % 2 then
me.right; me.clearAndMove; me.right
else
me.left; me.clearAndMove; me.left
end if
end for
end function