ComputerCraft Forums

ComputerCraft => Programs => Turtle Programs => Topic started by: informer on Feb 14, 2019, 02:37 am

Title: BTA - A Better Turtle API
Post by: informer on Feb 14, 2019, 02:37 am
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 (https://wiki.computercraft.cc/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:
    Functions:
        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:
        turn.
            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
pastebin (https://pastebin.com/MdD051uF)
Title: BTA - A Better Turtle API
Post by: Jigokusaru on Dec 04, 2019, 05:56 pm
I'm sorry I'm not sure how this is used. I tried bta.goTo() and did nothing. am i stupid?
Title: BTA - A Better Turtle API
Post by: informer on Aug 24, 2020, 05:25 am
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 (https://wiki.computercraft.cc/Vector_API) 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()
    ...
end

bta.goTo(vector, printLocation)

Sorry I wasn't clear about the usage!