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

Why won't my branch miner work?

Started by xXSmugMafiaXx, 09 December 2013 - 09:37 PM
xXSmugMafiaXx #1
Posted 09 December 2013 - 10:37 PM
The code: http://pastebin.com/tXjJ7HFC

It just gives me an error that there's an unusual symbol on line 17. How could I fix this? Is there anything else wrong with the code? This is my first program for computer craft, so I'm pretty new to lua. Any suggestions would help, thanks.
HurricaneCoder #2
Posted 10 December 2013 - 12:03 AM
I know your mistake because your answer variable is a string therefore you must set your distance = to a string for it to work. this is how you do it. line 17 where it said distance you need to put :

until tostring("distance") == answer
HurricaneCoder #3
Posted 10 December 2013 - 12:12 AM
I know your mistake because your answer variable is a string therefore you must set your distance = to a string for it to work. this is how you do it. line 17 where it said distance you need to put :

until tostring("distance") == answer


there is a lot of things wrong with this code




local distance = 0
local answer = 0
local answer2 = 0

function intro()
		print ("hello, how long would you like the tunnel to be?")
		answer = read()
		print ("how many strips?")
		answer2 = read()
		print ("starting...")
end

function strips()
repeat						   ----------------------repeat loop needs no end
		dig()
		distance = distance + 1
until distance == answer				  -------------- until tostring(distance) == answer
		turn.back()
  end								  ------------------ so this end is not suppose to be here
end

function dig()
  turtle.dig()
  turtle.forward()
  turtle.digUp()
end

function next()
		turtle.turnRight()
		turtle.forward()
		turtle.forward()
		turtle.turnRight()
end

function turn.back()			  ---------------- nil function you need to have turnBack you can't have a period
  turtle.turnRight()
  turtle.turnRight()
end							   -- this end the function turnBack.  are you sure you want to have an end it here?
  if distance == 0 then
		next()
  else
		turtle.moveforward()
		distance = distance - 1
end
end									---------extra end get rid of it

intro()
strips()
Edited on 09 December 2013 - 11:16 PM
Patric20878 #4
Posted 10 December 2013 - 12:44 AM
I know your mistake because your answer variable is a string therefore you must set your distance = to a string for it to work. this is how you do it. line 17 where it said distance you need to put :

until tostring("distance") == answer

Actually, it'd be:

until tostring(distance) == answer

Though, doesn't explain the unusual symbol thing he was talking about. Not using tostring() doesn't give an error.
H4X0RZ #5
Posted 10 December 2013 - 04:28 AM
I think turn.back() is the problem.
Declare a table called turn on the top of your code,then the turn.back() mistake is removed.


turn = {}
xXSmugMafiaXx #6
Posted 10 December 2013 - 07:16 PM
Pastebin: http://pastebin.com/jGG3Pnbf

Alright, so I made a post yesterday for a simple branch miner. Well, after some help and revision, I found a lot of flaws (not really surprised). But anyway, with this one I'm not getting errors (yet), but in the function "intro()," once I enter the amount for the length of the tunnel, it will completely skip the next 2 lines and go to "print ("starting…")," then mine 1 block in front and stop. Can anyone help?

P.S. Sorry if the fix is completely obvious. I'm very new to lua, and even newer to computer craft.
Lyqyd #7
Posted 10 December 2013 - 08:25 PM
Threads merged. Please stick to one topic for all questions about a given piece of code/project.