Posted 29 December 2012 - 03:09 AM
I am basically having a problem with where I place my "end". I am really not to this as I usually program in Java. Any help is appreciated, especially if you can describe a little more what went wrong.
curFacing = 0
curX = 0
curY = 0
curZ = 0
function fell()
if turtle.dig() then
turtle.dig()
turtle.forward()
turtle.select(2)
turtle.digUp()
turtle.up()
while turtle.compareUp() == true and turtle.digUp() do
turtle.digUp()
turtle.up()
end
while turtle.down() == true do
if turtle.getFuelLevel() == 0 then
turtle.select(1)
turtle.refuel(1)
turtle.select(2)
end
turtle.down()
end
print("Finished tree!")
end
end
function forward()
turtle.forward()
if curFacing == 0 then
curZ = curZ + 1
else if curFacing == 1 then
curX = CurX - 1
else if curFacing == 2 then
curZ = curZ - 1
else
curX = curX + 1
end
end
function left()
turtle.left()
if curFacing == 0 then
curFacing = 3
else
curFacing = curFacing - 1
end
saveData()
end
function right()
turtle.right()
if curFacing == 3 then
curFacing = 0
else
curFacing = curFacing + 1
end
saveData()
end
function up()
turtle.up()
curY = curY + 1
saveData()
end
function down()
turtle.down()
curY = curY - 1
saveData()
end
function saveData()
local file = fs.open("/data", "w")
file.writeLine(curX)
file.writeLine(curY)
file.writeLine(curZ)
file.writeLine(curFacing)
file.close()
end
function loadData()
local file = fs.open("/data", "r")
curX = file.readLine()
curY = file.readLine()
CurZ = file.readLine()
curFacing = file.readLine()
if curX == nil then
curFacing = 0
curX = 0
curY = 0
curZ = 0
print("No save data found!")
else if curX ~= 0 and curY ~= 0 and curZ ~= 0 then
print("Save data loaded!")
if curFacing == 0 then
curFacingString = "south"
else if curFacing == 1 then
curFacingString = "west"
else if curFacing == 2 then
curFacingString = "south"
else if curFacing == 3 then
curFacingString = "east"
end
print("I am at X="..curX..", Y="..curY..", Z="..curZ.."and I am facing "..curFacingString..".")
else
print("Save data loaded!")
print("I am at my home position")
end
end
-- Main function
loadData()