BTA - A Better Turtle API

Started by informer, Feb 14, 2019, 02:37 am

Previous topic - Next topic


Feb 14, 2019, 02:37 am Last Edit: Sep 21, 2020, 03:47 am by informer Reason: Clarification URL
After a decent amount of revision I'm going to release my turtle API to the public. It's pretty well commented so there shouldn't be much issue understanding it if you read through the code.

A caveat: I use gps for most if not all functions, I'll think about adding a way to keep your location with out it if people desire it.

Edit: any mention of a vector requires the Vector API
Edit 2: I added an gps-less mode, so it should now work without it. GPS is super beneficial, but it is lacking. The new implementation is hopefully better for earlier survival and potentially more accurate to your local environment if you are on a server.

Here is a quick rundown of the features added:
        calibrate() to the cardinal directions
        boxTo(destinationVector[, fn]) moves to every location between two coordinates
        goTo(vector[, fn]) moves the turtle to a specific vector
        move(direction[, fn][, count]) multiple times, foward-back-up-down
        refuel() checks inventory for fuel
        xMovement(distance[, fn]) moves the turtle along the x-axis
        yMovement(distance[, fn]) moves the turtle along the y-axis
        zMovement(distance[, fn]) moves the turtle along the z-axis
    Internal packages:
            north(), south, (etc..) face the four cardinal directions
            spin(direction[, count]) multiple times
            toCardinal(str) face cardinal direction by user input
            getDirection() get current direction as a string value

Code Select
pastebin get MdD051uF bta


I'm sorry I'm not sure how this is used. I tried bta.goTo() and did nothing. am i stupid?


Aug 24, 2020, 05:25 am #2 Last Edit: Aug 24, 2020, 05:29 am by informer
Quote from: Jigokusaru on Dec 04, 2019, 05:56 pmI'm sorry I'm not sure how this is used. I tried bta.goTo() and did nothing. am i stupid?

Hi, sorry I was inactive for awhile. I assume you did not include a destination vector? Here is an example on how to use that command with all steps needed.

Step one: Set up a GPS system included in the base OS.
Step two: Create a turtle with a modem attachment and download my script.
Step three: open lua by typing "lua" in the turtle
Step four: find a vector (xyz location) you would like the turtle to goto
Step five: create a new vector with that location
Step six: type bta.goTo(vector) where vector is the reference to the vector object you just made

Additionally you can have the turtle execute a command at every location between it's starting point and the final location by adding a reference to a function ie

function printLocation()

bta.goTo(vector, printLocation)

Sorry I wasn't clear about the usage!