This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wired2coffee's profile picture

Tortoise API

Started by Wired2coffee, 29 February 2012 - 02:53 AM
Wired2coffee #1
Posted 29 February 2012 - 03:53 AM
Will not mess up if it hits with obstacles!

Load it as if it were any other API!

Want to download it from a pastebin downloader? No problem!
http://pastebin.com/qURqLBp7


Use (API):
*Works on servers*
Use tortoise.up() instead of turtle.up() ;
Use tortoise.turnLeft() instead of turtle.turnLeft()
etc. (won't work with non-movement related turtle functions)
Tip: Refrain from back(), it doesn't work.

*NEW*
You can use tortoise.goto(x,y,z) to move to that area (if obstructed returns false).

x,y,z,d = tortoise.getXYZD() to get current coordinates. D stands for direction (north/south/east/west)
tortoise.printXYZD() to print current coordinates and direction.

Wired2coffee's Programs:
http://bit.ly/wlyKjx

What it Does:
It'll save coordinates of the turtle for later use, just use tortoise. instead of turtle.

How to set it up on your computer after API is installed:
1. Type Lua
2. Type tortoise.setUp()

Don't know how to install an API? It's simple!:
1. Go to your computercraft folder in your mods folder.
2. Go into the folder lua.
3. Go into the folder rom.
4. Drag tortoise into your apis folder!.

Spoiler

function forward()
file = io.open("tortoiseDir","r")
direction = file:read()
file:close()
file = io.open("tortoiseX","r")
x = file:read()
file:close()
file = io.open("tortoiseY","r")
y = file:read()
file:close()
file = io.open("tortoiseZ","r")
z = file:read()
file:close()
lawl = turtle.forward()
if lawl == true then
  if direction == "north" then
   fs.delete("tortoiseZ")
   file = io.open("tortoiseZ","w")
   z = tonumber(z)
   file:write(z-1)
   file:close()
  end
  if direction == "west" then
   fs.delete("tortoiseX")
   file = io.open("tortoiseX","w")
   x = tonumber(x)
   file:write(x-1)
   file:close()
  end
  if direction == "south" then
   fs.delete("tortoiseZ")
   file = io.open("tortoiseZ","w")
   z = tonumber(z)
   file:write(z+1)
   file:close()
  end
  if direction == "east" then
   fs.delete("tortoiseX")
   file = io.open("tortoiseX","w")
   x = tonumber(x)
   file:write(x+1)
   file:close()
  end
end
end
function getXYZD()
file = io.open("tortoiseDir","r")
direction = file:read()
file:close()
file = io.open("tortoiseX","r")
x = tonumber(file:read())
file:close()
file = io.open("tortoiseY","r")
y = tonumber(file:read())
file:close()
file = io.open("tortoiseZ","r")
z = tonumber(file:read())
file:close()
return x,y,z,direction
end
function printXYZD()
file = io.open("tortoiseDir","r")
direction = file:read()
file:close()
file = io.open("tortoiseX","r")
x = tonumber(file:read())
file:close()
file = io.open("tortoiseY","r")
y = tonumber(file:read())
file:close()
file = io.open("tortoiseZ","r")
z = tonumber(file:read())
file:close()
print(x.." "..y.." "..z.." "..direction)
end
function up()
file = io.open("tortoiseY","r")
y = file:read()
y = tonumber(y)
file:close()
lawl = turtle.up()
if lawl == true then
  fs.delete("tortoiseY")
  file = io.open("tortoiseY","w")
  if y < 126 and y >= 1 then
   file:write(y+1)
  else
   file:write(y)
  end
file:close()
end
end
function turnLeft()
file = io.open("tortoiseDir","r")
direction = file:read()
file:close()
fs.delete("tortoiseDir")
turtle.turnLeft()
file = io.open("tortoiseDir","w")
if direction == "west" then
  file:write("south")
end
if direction == "east" then
  file:write("north")
end
if direction == "south" then
  file:write("east")
end
if direction == "north" then
  file:write("west")
end
file:close()
end
function turnRight()
file = io.open("tortoiseDir","r")
direction = file:read()
file:close()
fs.delete("rm","tortoiseDir")
turtle.turnRight()
file = io.open("tortoiseDir","w")
if direction == "west" then
  file:write("north")
end
if direction == "east" then
  file:write("south")
end
if direction == "south" then
  file:write("west")
end
if direction == "north" then
  file:write("east")
end
file:close()
end
function setUp()
term.clear()
term.setCursorPos( 1, 1 )
print("What direction is your turtle currently facing? (lower case)")
out = read()
file = io.open("tortoiseDir","w")
file:write(out)
file:close()
print("Current X Coord?")
out = read()
file = io.open("tortoiseX","w")
file:write(out)
file:close()
print("Current Z Coord?")
out = read()
file = io.open("tortoiseZ","w")
file:write(out)
file:close()
print("Current Y Coord?")
out = read()
file = io.open("tortoiseY","w")
file:write(out)
file:close()
term.clear()
term.setCursorPos( 1, 1 )
print("Finished")
end
function down()
file = io.open("tortoiseY","r")
y = file:read()
y = tonumber(y)
file:close()
lawl = turtle.down()
fs.delete("tortoiseY")
if lawl == true then
  file = io.open("tortoiseY","w")
  if y <= 126 and y > 1 then
   file:write(y-1)
  end
else
  file = io.open("tortoiseY","w")
  file:write(y)
end
file:close()
end
function goto(x,y,z)
xx,yy,zz,dd = tortoise.getXYZD()
if yy < y then
  for i = 1,math.abs(yy-y) do
   tortoise.up()
  end
elseif yy > y then
  for i = 1,math.abs(y-yy) do
   tortoise.down()
  end
end
if xx < x then
  for i = 1,4 do
   lol,lol,lol,dd = tortoise.getXYZD()
   if dd ~= "east" then
	tortoise.turnLeft()
   end
  end
  for i = 1,math.abs(xx-x) do
   tortoise.forward()
  end
elseif xx > x then
  for i = 1,4 do
   lol,lol,lol,dd = tortoise.getXYZD()
   if dd ~= "west" then
	tortoise.turnRight()
   end
  end
  for i = 1,math.abs(x-xx) do
   tortoise.forward()
  end
end
if zz < z then
  for i = 1,4 do
   lol,lol,lol,dd = tortoise.getXYZD()
   if dd ~= "south" then
	tortoise.turnLeft()
   end
  end
  for i = 1,math.abs(zz-z) do
   tortoise.forward()
  end
elseif zz > z then
  for i = 1,4 do
   lol,lol,lol,dd = tortoise.getXYZD()
   if dd ~= "north" then
	tortoise.turnRight()
   end
  end
  for i = 1,math.abs(z-zz) do
   tortoise.forward()
  end
end
xx,yy,zz,dd = tortoise.getXYZD()
if xx ~= x or yy ~= y or zz ~= z then
  print("Obstructed during flight.")
  return false
else
  return true
end
end

Download:
FuzzyPurp #2
Posted 01 March 2012 - 05:43 AM
Guess you never saw the Alias program?
Noodle #3
Posted 04 March 2012 - 02:51 AM
xD with above

It's just X,Y,Z, coordinates…
Wired2coffee #4
Posted 04 March 2012 - 05:32 AM
xD with above

It's just X,Y,Z, coordinates…
As well as direction facing!
Zer0t3ch #5
Posted 13 March 2012 - 08:12 PM
Well I love it!!!