Jump to content




Digging Program Working Unexpectedly


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

#1 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 October 2013 - 06:05 PM

I have made a simple digging program that will attempt to fetch a turtle location via GPS and if it fails asking the user for manual input of the Y coordinate. It then calculates (Y level - 10) how far it needs to mine until it hits lava layer and will place a water bucket so that you can jump down.

The turtle stops, spews out the "Unexpected Error" message I built into the program multiple times into the console and ends the program if it hits a cave midway and there is no block underneath it.

My code is available here:
pastebin get nKy2QuPX
or
Spoiler


Thanks for your help.

#2 campicus

  • Members
  • 164 posts

Posted 17 October 2013 - 06:10 PM

turtle.detectDown() can only return true or false, so your conditional if should just be:

  if turtle.detectDown() then
    turtle.digDown()
    turtle.down()
    checkFuel()
  else
    turtle.down()
	checkFuel()
  end
  blocksdug = blocksdug + 1


#3 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 October 2013 - 07:16 PM

About to check this, I'm assuming I don't indent checkfuel()?

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 October 2013 - 07:55 PM

The Lua interpreter doesn't care whether you do or don't, but for the sake of human readability it's best not to.

#5 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 October 2013 - 08:00 PM

Oh yeah, my bad. Got confused with Python, which will whine at you if you don't indent correctly. The two languages are so similar.

EDIT:
Edited the script a tad, but the thing won't place the water bucket at the end, however it does dig to lava layer without problems. The script in the original post has been updated.

#6 campicus

  • Members
  • 164 posts

Posted 17 October 2013 - 09:40 PM

Sorry about the indent, it wasn't indented when I wrote it :s


No idea why your turtle won't place the water sorry :s

Just an aside, it won't matter if your "turtle.digDown()" returns false, so you could just have:

turtle.digDown()
turtle.down()
checkFuel()
blocksdug = bocksdug + 1

instead of:
  if turtle.detectDown() then
	turtle.digDown()
	turtle.down()
	checkFuel()
  else
	turtle.down()
	checkFuel()
  end
  blocksdug = blocksdug + 1


#7 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 18 October 2013 - 07:01 PM

Thanks, just saw no point in having the turtle swing the pickaxe when it doesn't need to and waste time (or does it?). As I said, I'm a noob.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users