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

[LUA] [HELP] Help with turtle mining program error

Started by rob13, 02 February 2013 - 09:29 AM
rob13 #1
Posted 02 February 2013 - 10:29 AM
I'm trying to write a basic mining script for turtles. It's designed to dig a 1x1x50 tunnel horizontally and check the rows above, below, and to each side of it for each of four items (gravel, dirt, stone, and marble, although it could be any items). It will dig the item if it is not one of the specified four. It also contains a function to ensure that gravel doesn't prevent it from going the full 50 blocks horizontally.

Unfortunately, I'm running into an error. I have no clue what's causing it. I'm a relative novice with LUA, so I was hoping for some help. Here's the error:

"bios:338: [string "mine"]:53: 'end' expected (to close 'function' at line 7)


function check()
if (turtle.compare(1)==false) and (turtle.compare(2)==false) and (turtle.compare(3)==false) and (turtle.compare(4)==false) then do
turtle.dig()
end
end

function checkDown()
if (turtle.compareDown(1)==false) and (turtle.compareDown(2)==false) and (turtle.compareDown(3)==false) and (turtle.compareDown(4)==false) then do
turtle.digDown()
end
end

function checkUp()
if (turtle.compareUp(1)==false) and (turtle.compareUp(2)==false) and (turtle.compareUp(3)==false) and (turtle.compareUp(4)==false) then do
turtle.digUp()
end
end

function gravel()
while (turtle.compare(1)==true) do
turtle.dig()
end
end

local i = 1

while i<=50 do
turtle.dig()
gravel()
turtle.forward()
checkUp()
checkDown()
turtle.turnLeft()
check()
turtle.turnRight()
turtle.turnRight()
check()
turtle.turnLeft()
i=i+1
end

while i==51 do
turtle.turnRight()
turtle.turnRight()
i=i+1
end

while (i>=52) and (i<=101) do
turtle.forward()
i=i+1
end

end
Edited by
rob13 #2
Posted 02 February 2013 - 10:32 AM
I done screwed up the title. I forgot to type the whole thing. Meant for it to say [LUA] [HELP] Help with turtle mining program error
Lyqyd #3
Posted 02 February 2013 - 11:09 AM
I adjusted the title for you, but for future reference, if you use the full editor to edit the first post, you can change your own topic title.
KingMachine #4
Posted 02 February 2013 - 11:16 AM
remove the last end
rob13 #5
Posted 02 February 2013 - 11:26 AM
Originally I didn't have that there, but that just gave the same error, except the line changed to the line where the checkUp function began.
KingMachine #6
Posted 02 February 2013 - 11:33 AM

function check()
if (turtle.compare(1)==false) and (turtle.compare(2)==false) and (turtle.compare(3)==false) and (turtle.compare(4)==false) then do
turtle.dig()
end
end
function checkDown()
if (turtle.compareDown(1)==false) and (turtle.compareDown(2)==false) and (turtle.compareDown(3)==false) and (turtle.compareDown(4)==false) then do
turtle.digDown()
end
end
function checkUp()
if (turtle.compareUp(1)==false) and (turtle.compareUp(2)==false) and (turtle.compareUp(3)==false) and (turtle.compareUp(4)==false) then do
turtle.digUp()
end
end
function gravel()
while (turtle.compare(1)==true) do
turtle.dig()
end
end
 
function main()
local i = 1
while i<=50 do
turtle.dig()
gravel()
turtle.forward()
checkUp()
checkDown()
turtle.turnLeft()
check()
turtle.turnRight()
turtle.turnRight()
check()
turtle.turnLeft()
i=i+1
end
while i==51 do
turtle.turnRight()
turtle.turnRight()
i=i+1
end
while (i>=52) and (i<=101) do
turtle.forward()
i=i+1
end
end
main()

Try this (wrapped the last part in a main function and then called it first, since it would technically be the first thing run according to the "compiler".
rob13 #7
Posted 02 February 2013 - 11:39 AM
Same error.
KonkieDong #8
Posted 17 May 2013 - 10:37 PM
yo farily certain that this thread is dead but if it is not .. your issue is that you have added a do after the then statements.. so basically when you use the conditional "if" you used "then" .. however when you are using "for" or "while" then you use "do"

function check()
if (turtle.compare(1)==false) and (turtle.compare(2)==false) and (turtle.compare(3)==false) and (turtle.compare(4)==false) then
turtle.dig()
end
end
function checkDown()
if (turtle.compareDown(1)==false) and (turtle.compareDown(2)==false) and (turtle.compareDown(3)==false) and (turtle.compareDown(4)==false) then
turtle.digDown()
end
end
function checkUp()
if (turtle.compareUp(1)==false) and (turtle.compareUp(2)==false) and (turtle.compareUp(3)==false) and (turtle.compareUp(4)==false) then
turtle.digUp()
end
end
function gravel()
while (turtle.compare(1)==true) do
turtle.dig()
end
end
local i = 1
while i<=50 do
turtle.dig()
gravel()
turtle.forward()
checkUp()
checkDown()
turtle.turnLeft()
check()
turtle.turnRight()
turtle.turnRight()
check()
turtle.turnLeft()
i=i+1
end
while i==51 do
turtle.turnRight()
turtle.turnRight()
i=i+1
end
while (i>=52) and (i<=101) do
turtle.forward()
i=i+1
end