Jump to content




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


  • You cannot reply to this topic
7 replies to this topic

#1 rob13

  • Members
  • 7 posts

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 Lyqyd, 02 February 2013 - 11:08 AM.
added code tags


#2 rob13

  • Members
  • 7 posts

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

#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#4 KingMachine

  • Members
  • 122 posts

Posted 02 February 2013 - 11:16 AM

remove the last end

#5 rob13

  • Members
  • 7 posts

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.

#6 KingMachine

  • Members
  • 122 posts

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".

#7 rob13

  • Members
  • 7 posts

Posted 02 February 2013 - 11:39 AM

Same error.

#8 KonkieDong

  • New Members
  • 1 posts

Posted 17 May 2013 - 09: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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users