Posted 27 July 2013 - 04:21 AM
This error drives me nuts…
here is the code
It just gives me "multiple points"… no line or anything like that…
here is the code
Spoiler
--[[
Xyexs Smart mining turtle(SMT) 3.0
Set up:
Get this file from pastebin
Run the program
Follow the instructions
Change log:
3.0.0
Added change log.
Rewritten (mostly, copied a bit).
Added a nifty interface.
Fixed a common problem that caused it to lose its position after chunk reload at times.
Prettied up the code.
]]
--Variables------
local width = nil
local depth = nil
local VERSION = "3.0.0"
local moveArray = {}--Contains all movements
local noteArray = {"","","",""}--Contains all notifications
local lastFuelLevel = nil -- What the fuel level was at before reboot
local x = nil
local y = nil--The turtles coordinates(Y is reversed)
local z = nil
local facing = nil
local shouldBeAtX ={}
local shouldBeAtY ={}--reversed
local shouldBeAtZ ={}
local shouldBeFacing ={}
local genIndex = 0
local oldFuelLevel = nil -- session persistence things
local junkSlots = nil
local selectedSlot = 1 --Umhh.... do I need to comment here?
-----------------
--Functions------
--File functions
function save()-- Saves crucial variables to a file ( this is required for session persistence)
local w = fs.open("/miningData","w")
w.writeLine(x)
w.writeLine(y)
w.writeLine(z)
w.writeLine(isAtIndex)
w.writeLine(width)
w.writeLine(depth)
w.writeLine(turtle.getFuelLevel())
w.writeLine(junkSlots)
w.close()
end
function load()--Loads saved data
if fs.exists("/miningData") then
local r = fs.open("/miningData","r")
x = r.readLine()
y = r.readLine()
z = r.readLine()
isAtIndex = r.readLine()
width = r.readLine()
depth = r.readLine()
oldFuelLevel = r.readLine()
junkSlots = r.readLine()
r.close()
else
term.clear()
term.setCursorPos(1,1)
print("Hi, let's set up before I start mining!\n\n")
print("What is the turtles current y coordinate?")
depth = read()
while type(depth) ~= number do
print("Umh... That's not a number- try again!")
depth=read()
end
depth = tonumber(depth) - 4
print("Awesome! Now how wide do you want it? It's a square so... diameter?")
width = read()
while type(width) ~= number do
print("Umh... That's not a number- try again!")
width=read()
end
width = tonumber(width)
print("\nOne more thing, put blocks you want me to ignore in slots 1-4 and press any key :D/>/>/>")
os.pullEvent("key")
for i = 1,4 do
if turtle.getItemCount(i) ~= 0 then
junkSlots = junkSlots + 1
end
end
print("Okie , I'll start mining now")
sleep(0.5)
end
end
--UI functions
function updateProgressBar()--Resets and prints the progress bar
local percentage = math.ceil(isAtIndex / #moveArray) --Stores the percentage completed, 20 % would be 0.20
term.setCursorPos(2,2)
term.write("[ ]")
term.setCursorPos(3,2)
for i = 1, math.ceil(percentage * 34) do
term.write("X")
end
term.setCursorPos(17,1)
term.write(" ")
term.setCursorPos(17,1)
term.write(percentage * 100.." %")
end
function updateNotes()--Updates the notifications
for i = 6,12 do
term.setCursorPos(19,i)
term.write(" ")
end
local noteCounter = 1
for i = 20,26, +2 do
term.setCursorPos(i,6)
term.write(noteArray[noteCounter])
noteCounter = noteCounter + 1
end
end
function updateScreen() -- Updates the UI
term.clear()
updateProgressBar()
term.setCursorPos(1,4)
print("-----------------v---------------------\n -\n -\n -\n -\n -\n -\n -\n ---------------------\n - SMT "..version.." by Xyexs")
updateProgressBar()
updateNotes()
end
function addNote(local note) -- Adds a notification with a maximum of 21 chars
noteArray[3] = noteArray[2]
noteArray[2] = noteArray[1]
noteArray[1] = note
updateNotes()
end
--Movement etc. functions
function face(local direction)
local testFacing = facing
local leftCounter= 0
local rightCounter= 0
while testFacing ~= direction do
testFacing = (testFacing - 1) %4
leftCounter = leftCounter + 1
end
testFacing =facing
while testFacing ~= direction do
testFacing = (testFacing + 1) %4
rightCounter = rightCounter + 1
end
while facing ~= direction do
if leftCounter > rightCounter then
right()
else
left()
end
end
end
function goto(local goX,goY,goZ,goFace) -- moves to the specified location
if goZ ~= z then
face(1)
while y ~= 1 do
forw()
end
face(2)
while x ~= 1 do
forw()
end
while y ~= goY do
if y < goY then
up()
elseif y > go then
down()
else
term.clear()
term.setCursorPos(1,1)
error("Tell Xyexs his logic is not logical :P/>/>/>")
end
end
end
face(0)
while x ~= goX do
forw()
end
face(3)
while y ~= goY do
forw()
end
face(goFace)
end
function drop(local fslot,lslot) -- Drops the inventory content from fslot to lslot
for local i=fslot,lslot do
turtle.select(i)
if turtle.drop() == false and turtle.getItemCount(i) ~= 0then
addNote("Can't drop- full?")
end
while turtle.drop() == false and turtle.getItemCount(i) ~= 0 do
sleep(2)
end
end
end
function refuel() -- checks the fuel level and returns to surface if it needs more fuel
--Meh, ill write this later :D/>/>/>... right now I just want to get a test version out
end
function dig()
turtle.dig()
end
function digUp()
turtle.digUp()
end
function digDown()
turtle.digDown()
end
function left()
turtle.left()
facing = (facing - 1) % 4
end
function right()
turtle.right()
facing = (facing + 1) % 4
end
function forw()
if turtle.forward() == false then -- this is just anti-spamming
addNote("Trouble moving...")
while turtle.forward() == false do
dig()
end
end
if facing == 0 then
x = x + 1
elseif facing == 1 then
y = y - 1
elseif facing == 2 then
x = x - 1
elseif facing == 3 then
y = y + 1
else
term.clear()
term.setCursorPos(1,1)
error("ERROR! INVALID FACING VARIABLE, contact Xyexs immediately! (:o/>/>/>, dramatic)")
end
refuel()
end
function up()
if turtle.up() == false then
addNote("Trouble moving up")
while turtle.up() == false do
digUp()
end
end
z = z - 1
refuel()
end
function down()
if turtle.down() == false then
addNote("Trouble moving down")
while turtle.down() == false do
digDown()
end
end
z = z + 1
refuel()
end
function compareDig()
if junkSlots > 0 then
local isJunkDown = false
local isJunkUp = false
if selectedSlot == 1 then
for i = 1 , junkSlots do
turtle.select(i)
if turtle.compareUp()== true then
isJunkUp = true
end
if turtle.compareDown()== true then
isJunkDown = true
end
end
else
for i = junkSlots , 1, -1 do
turtle.select(i)
selectedSlot = i
if turtle.compareUp()== true then
isJunkUp = true
end
if turtle.compareDown()== true then
isJunkDown = true
end
end
end
if isJunkUp == false then
digUp()
end
if isJunkDown == false then
digDown()
end
else
digUp()
digDown()
end
end
--Path generating functions
function insertGen(local shouldX,shouldY,shouldZ,shouldFace,move)--inserts the variables to the correct arrays
genIndex = genIndex + 1
shouldBeAtX[genIndex] = shouldX
shouldBeAtY[genIndex] = shouldY
shouldBeAtZ[genIndex] = shouldZ
shouldBeFacing[genIndex] = shouldFace
moveArray[genIndex] = move
end
function genDig()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],dig)
end
function genDigUp()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],digUp)
end
function genDigDown()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],digDown)
end
function genCompareDig()
if moveArray[genIndex] ~= nil then -- Because this generates first I had to do this :D/>/>/>
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],compareDig)
else
insertGen(1,1,1,0,compareDig)
end
end
function genRight()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],(shouldBeFacing[genIndex]+1) % 4,right)
end
function genLeft()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex],(shouldBeFacing[genIndex]+1) % 4,left)
end
function genForw()
if shouldBeFacing[genIndex] == 0 then
insertGen(shouldBeAtX[genIndex] + 1,shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],forw)
elseif shouldBeFacing[genIndex] == 1 then
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex] - 1,shouldBeAtZ[genIndex],shouldBeFacing[genIndex],forw)
elseif shouldBeFacing[genIndex] == 2 then
insertGen(shouldBeAtX[genIndex] - 1,shouldBeAtY[genIndex],shouldBeAtZ[genIndex],shouldBeFacing[genIndex],forw)
elseif shouldBeFacing[genIndex] == 3 then
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex] + 1,shouldBeAtZ[genIndex],shouldBeFacing[genIndex],forw)
else
term.clear()
term.setCursorPos(1,1)
error("ERROR! INVALID (gen)FACING VARIABLE, contact Xyexs immediately! (:o/>/>/>, dramatic)")
end
end
function genDown()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex] + 1,shouldBeFacing[genIndex],down)
end
function genUp()
insertGen(shouldBeAtX[genIndex],shouldBeAtY[genIndex],shouldBeAtZ[genIndex] - 1,shouldBeFacing[genIndex],down)
end
function genDigRow()
for i = 1, width - 1 do
genCompareDig()
genDig()
genForw()
end
end
function genDigLayer() -- should be more loops in this one... just cant find a good solution to that...
if width % 2 == 0 then
for i = 1 , width / 2 - 1 do
genDigRow()
genCompareDig()
genLeft()
dig()
genForw()
genLeft()
genDigRow()
genCompareDig()
genRight()
dig()
genForw()
genRight()
end
genDigRow()
genCompareDig()
genLeft()
dig()
genForw()
genLeft()
genDigRow()
genCompareDig()
genLeft()
for i = 1, size-1 do
genForw()
end
genLeft()
else
for i = 1, (size - 1)/2 do
genDigRow()
genCompareDig()
genLeft()
dig()
genForw()
genLeft()
genDigRow()
genCompareDig()
genRight()
dig()
genForw()
genRight()
end
genDigRow()
genCompareDig()
genRight()
while y ~= 1 do
genForw()
end
genRight()
while x ~= 1 do
genForw()
end
genLeft()
genLeft()
end
end
function genPath()
addNote("Generating path...")
for i = 1, depth do
genDigLayer()
end
for i = 1, 3 do
genDown()
if shouldBeAtY == depth then
break
end
end
end
-----------------
--Program--------
load()
updateScreen()
genPath()
if turtle.getFuelLevel() ~= oldFuelLevel then
goto(shouldBeAtX[isAtIndex],shouldBeAtY[isAtIndex],shouldBeAtZ[isAtIndex],shouldFace[isAtIndex])
end
repeat
moveArray[isAtIndex]()
isAtIndex = isAtIndex + 1
save()
updateProgressBar()
until isAtIndex == #moveArray
updateProgressBar()
fs.delete("/miningData")
fs.delete("/startup")
goto(1,1,1,2)
drop(1,16)
face(0)
term.clear()
term.setCursorPos(1,1)
print("If you liked ... or didn't like .. the script, leave a comment and let me know!\n\n // Xyexs")
-----------------
It just gives me "multiple points"… no line or anything like that…