ComputerCraft Forums

ComputerCraft => Programs => APIs and Utilities => Topic started by: Valvate on Oct 04, 2018, 02:13 AM

Title: Coordinate management library (beta)
Post by: Valvate on Oct 04, 2018, 02:13 AM
Hey guys, this is my first forum post so my formatting is going to suck (sorry!)

i wrote a library / api / module for coordinate management, here (https://github.com/itsyourboychipsahoy/Random/blob/master/lib.lua) is the github,
you can download it to your turtle with

wget https://raw.githubusercontent.com/itsyourboychipsahoy/Random/master/lib.lua lib.luaimport it with
local t = require('lib') or
local t = dofile('lib.lua')
It has all the normal turtle movement functions turning functions and digging functions, except it keeps track of coordinates and blocks dug.
also it can save positions and go back to them later
and move to coordinates (turtle starts at 0,0,0 facing north)
t.saveCurrentPos('home')
t.forward()
t.digUp()
t.turnRight()
t.up()
print('I have dug '..t.blocks_dug..' Blocks!')
t.gotoPos('home')
all the functions return true when they worked and return false when they failed (just like the turtle api!)
if you have any questions post a comment or ask me on discord :D

this is still a work in progress so please tell me how i can make it better :))

EDIT: if someone could tell me how to make the look function better that would be great, right now it just turns right until its at the correct orientation.
EDIT2: thanks Incin :D
EDIT3: added a bunch of test stuff that might not work
Title: Cordanite management library (beta)
Post by: Incin on Oct 04, 2018, 04:04 AM
First of all, it's spelled 'coordinate' :P

I've used this in the past:

function t.look(direction)
  if direction == orientation then return end

  if (direction - orientation) % 2 == 0 then
    t.turnLeft()
    t.turnLeft()
  elseif (direction - orientation) % 4 == 1 then
    t.turnRight()
  else
    t.turnLeft()
  end
end

The way it works is the following:
Title: Cordanite management library (beta)
Post by: Valvate on Oct 04, 2018, 02:43 PM
thanks Incin, i'm going to use what you said. :D
(it was hardcore triggering me when he turned right 3 times to get the correct orientation :P)