Jump to content




End expected


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

#1 applesauce10189

  • Members
  • 162 posts

Posted 04 January 2014 - 09:17 PM

It's a turtle mining program, idk what to do, I added end over and over one at a time and it kept giving me the message so then I thought maybe I had too many, so I got rid of one of two end's and still got the error,

function emptyInventory()
  for i = 3, 16 do
    turtle.select(i)
    turtle.dropDown(64)
  end
end

function gravityCheck()
  if  turtle.dig() == true then 
    turtle.dig() until turtle.dig() == false
  end
end

function appleMine()
  while true do
    for i = 1,60 do
      turtle.select(1)
      turtle.digDown()
      turtle.down()
      turtle.digDown()
      turtle.down()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.turnLeft()
      turtle.turnLeft()
      turtle.dig()
      gravityCheck()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.forward()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.turnLeft()
      turtle.turnLeft()
      turtle.dig()
      gravityCheck()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.forward()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.turnLeft()
      turtle.turnLeft()
      turtle.dig()
      gravityCheck()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.forward()
      turtle.turnRight()
      turtle.dig()
      gravityCheck()
      turtle.turnLeft()
      turtle.turnLeft()
      turtle.forward()
      turtle.dig()
      gravityCheck()
      turtle.turnRight()
      turtle.back()
      turtle.back()
      turtle.up()
      turtle.placeDown()
      emptyInventory()
      appleFuel()
    end
  end
end
function appleFuel()
  if turtle.getFuelLevel() <= 50 then
    turtle.select(2)
    turtle.placeUp()
    turtle.suckUp()
    turtle.refuel(64)
    turtle.digUp()
  end
end
turtle.select(1)
appleMine()

note to self, when copy/pasting from pastebin use raw paste data or the website will destroy your code whether you use [ code ] or [ spoiler ]

Edited by applesauce10189, 04 January 2014 - 09:16 PM.


#2 Bomb Bloke

    Hobbyist Coder

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

Posted 04 January 2014 - 09:24 PM

Did you mean?:

function gravityCheck()
  while turtle.dig() do end
end


#3 applesauce10189

  • Members
  • 162 posts

Posted 04 January 2014 - 09:29 PM

I'm new to coding, so thanks for the help,

#4 applesauce10189

  • Members
  • 162 posts

Posted 04 January 2014 - 09:35 PM

New problem, it just turns to the right and stops the entire program. The previous version of the program *cough cough* THIS http://www.computerc...turtle-program/ *cough cough* worked perfectly, if you want to know the difference between this version and the other one, the only addition to this version is the function gravityCheck() and putting it to use in a couple spots. Quick edit. It also turns off after a few seconds.
Yet another edit, I think this might be a client problem not code, I broke and placed the turtle and now I can't even type into it, and every now and then when I place it, it doesn't even turn on when I open the GUI.
Third and hopefully last edit. Exiting and coming back to my single player world seemed to fix it. Still turns to the right and turns off though.

Edited by applesauce10189, 04 January 2014 - 09:55 PM.


#5 Bomb Bloke

    Hobbyist Coder

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

Posted 04 January 2014 - 10:17 PM

Hrm. What do you mean by "stops the whole program"? Produces an error? If so, what? Or does it just stall, and not do anything at all? Does it not dig, or move downwards, at any point? Please be precise about what happens, and if you're not sure about exactly which line it's sticking on, add print statements in until you are.

#6 applesauce10189

  • Members
  • 162 posts

Posted 04 January 2014 - 10:21 PM

Basically, it digs down, doesn't go down as it should, probably out of fuel actually, but it turns right, then the turtle itself turns off. Quick edit. I added little checkpoints in the program. Every time appleMine() does something it prints a message. It dug right after turning right. but it might be stopping on the middle of gravityCheck() and not showing the checkpoint.

Edited by applesauce10189, 05 January 2014 - 09:30 AM.


#7 applesauce10189

  • Members
  • 162 posts

Posted 05 January 2014 - 09:38 AM

Okay, so, added checkpoints and now I know it's the while turtle.dig() do end part that's screwing up the program. It starts but doesn't end. Maybe put a break in there? I'll edit the code a bit and show you the code afterwards and I'll tell you if it works or not.


Here's the new code. It says there's no loop to break on line 9.
Spoiler

Edited by applesauce10189, 05 January 2014 - 09:54 AM.


#8 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 05 January 2014 - 10:00 AM

Replace "break" with "return":
function gravityCheck()
  print("Beginning 'while true do' statement.")
  while turtle.dig do end
  if turtle.dig() == false then
    return
  end
  print("while true do statement broken.")
end
You can only use break inside of loops, and using "return" will stop the function at that point.

#9 Bomb Bloke

    Hobbyist Coder

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

Posted 05 January 2014 - 11:11 AM

Or better yet, ditch the "if" block entirely.

#10 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 05 January 2014 - 06:04 PM

function gravityCheck()
	print("Beginning 'while true do' statement.")
	while turtle.dig do end
		if turtle.dig() == false then
			break
		end
	print("while true do statement broken.")
end

What Bomb Block said would be the ideal solution:
function gravityCheck()
	print("Beginning 'while true do' statement.")
	while turtle.dig() do end
	print("while true do statement broken.")
end

Your original code crashed because you ended the while loop before the if statement. You wanted to end the while loop after the if statement. Also, you weren't calling turtle.dig in the 'while turtle.dig do', you were only checking if it was defined, which it always will be for a turtle (unless someone deletes it).

Edited by electrodude512, 05 January 2014 - 06:08 PM.


#11 applesauce10189

  • Members
  • 162 posts

Posted 05 January 2014 - 07:51 PM

The program's fixed and working fine. New problem at hand that is just now appearing. Not sure why it didn't happen before but after adding/fixing gravityCheck() it's just now happening, so, basically, the program is supposed to dig a staircase down and such, for every level or so it goes down, it goes back 2 goes up and places the item/fuel chests, refuels and empties the inventory. here's the problem, it doesn't go back 2, it either goes back 1 or not at all, then when it tries to empty inventory and refuel, it gets nothing achieved.

#12 subzero22

  • Members
  • 97 posts

Posted 08 January 2014 - 01:43 PM

is it trying to back up into a block? if so turtles can't dig backwards as far as I know. also what kind of mining program is it suppose to be or is it just a stair one?





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users