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

[Lua] Need help with program

Started by fireiscoal, 16 May 2013 - 02:01 PM
fireiscoal #1
Posted 16 May 2013 - 04:01 PM
Title: Ask a Pro
[Lua] Need help with program
Its a "Auto=Pilot" program that I'm working on and I would like some assistance
Program so far:

local a = vector.new(gps.locate())
turtle.forward()
local b = vector.new(gps.locate())
turtle.back()
--Tells direction
if a.x < b.x then
local d = ("East")
end
if a.x > b.x then
local d = ("West")
end
if a.z < b.z then
local d = ("South")
end
if a.z > b.z then
local d = ("North")
end
--Part of "Planning Path"
print("Currently Facing: ",d)
print("Currently at: ",a)
term.write("X: ")
local x = read()
term.write("Y: ")
local y = read()
term.write("Z: ")
local z = read()
local g = vector.new(x, y, z)
--Planning Path WIP...
local p = g - a
local n, n2, n3 = math.abs(p.x), math.abs(p.y), math.abs(p.z)
print("X Distance: ", n, "\nY Change: ", n2, "\nZ Distance: ", n3, "\nTotal Distance: ", (n + n2 + n3))
local f = turtle.getFuelLevel()
if f < (n + n2 + n3) then
print("Need more fuel")
end
I would apprecate it if someone would help me with this.
CtrlAltElite #2
Posted 17 May 2013 - 01:36 PM
What do you want help with? You need to be more descriptive.
fireiscoal #3
Posted 20 May 2013 - 10:43 AM
I need help with the part of where it knows which way to go, the part where when you input the destination,

term.write("X: ")
local x = read()
term.write("Y: ")
local y = read()
term.write("Z: ")
local z = read()
local g = vector.new(x, y, z)
Thats what the destination is at, so I would say the part where it tells it which direction and how far.
Like this(Just off the top of my head ATM)

local t = g - a
if t.x > a.x and d=="East" then
for 0, 1, n do
turtle.dig()
turtle.forward()
end
Like it know which way to go and then it goes for the given amount then turns and goes till it reaches the destination.