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

ShaftminerV2

Started by Zatilla7, 16 April 2014 - 07:11 PM
Zatilla7 #1
Posted 16 April 2014 - 09:11 PM
Heya

I'va lately been brushing up on my Computer Craft coding. While it's not a masterpeice I've been updating my old codes.
The latest has been the Shaftminer program. A mining code for early game which goes down in the earth then dig a 1x2 mineshaft while poking into the walls so you can then manually mine the good bits.

The renewed code is not working in the style of not even launching


function SideMine()
  turtle.dig()
  if turtle.forward() then
  print ""
	else
	 turtle.dig()
	  turtle.forward()
end
function mine()
  turtle.dig()
   if turtle.forward() then
	turtle.digDown()
	 else
	  turtle.dig()
	   turtle.forward()
		turtle.digDown()
	end
end
term.write (Booting up Shaftminer V2)
wait(1)
print "How many blocks down would you like me to dig?"
d = read()
for i=1,d,1 do
turtle.dig()
  turtle.digDown()
   turtle.down()
	turtle.select(1)
	 turtle.place()
end
print "Mineshaft done. Shuting down. Bye"
print "Decent finished. Mineshaft iniciating"
for i=1,1,2 do
turtle.turnRight()
end
turtle.up()
for i=1,20,1 do
  mine()
   mine()
	mine()
	turtle.turnRight()
	 sideMine()
	  sideMine()
	   sideMine()
		turtle.turnRight()
		 turtle.turnRight()
		  turtle.forward()
		   turtle.forward()
			turtle.forward()
			 turtle.forward()
			  sideMine()
			   sideMine()
				sideMine()
				 turtle.turnRight()
				  turtle.turnRight()
				   turtle.forward()
					turtle.forward()
					 turtle.forward()
					  turtle.turnLeft()
end
end


Thank you for your time. I'll be uploading this when it's fixed
Exerro #2
Posted 16 April 2014 - 11:02 PM
You've missed an end for your SideMine function and put an extra one on the end of your code, therefore lua thinks everything is in the SideMine function and as you never call that at the end of your code (below the ends) nothing ever runs.
To fix this, add an end on line 9 and remove the last end.
Also, a word of advice: using that style of tabbing makes things very hard to interpret and is probably why you missed this problem. Try indenting when there are code blocks (ifs,loops,functions) and (de-intenting?) when there is an end.

Edit: Here is the formatted code (fixed (should be anyway))


function SideMine()
turtle.dig()
if turtle.forward() then
  print ""
else
  turtle.dig()
  turtle.forward()
end
end -- you missed this!
function mine()
turtle.dig()
if turtle.forward() then
  turtle.digDown()
else
  turtle.dig()
  turtle.forward()
  turtle.digDown()
end
end
term.write ("Booting up Shaftminer V2") -- this should have been a string
wait(1)
print "How many blocks down would you like me to dig?"
d = read()
for i=1,d,1 do
turtle.dig()
turtle.digDown()
turtle.down()
turtle.select(1)
turtle.place()
end
print "Mineshaft done. Shuting down. Bye"
print "Decent finished. Mineshaft iniciating"
for i=1,1,2 do
turtle.turnRight()
end
turtle.up()
for i=1,20,1 do
mine()
mine()
mine()
turtle.turnRight()
sideMine()
sideMine()
sideMine()
turtle.turnRight()
turtle.turnRight()
for i = 1, 4 do -- shortens it a bit (and you dont need to do 1, 4, 1 by the way)
  turtle.forward()
end
sideMine()
sideMine()
sideMine()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end
-- you don't need this end
Edited on 16 April 2014 - 09:08 PM
Zatilla7 #3
Posted 17 April 2014 - 10:39 AM
Thanks. The code is now atleast booting up but I still a have a few bugs in the code it seems. Anyways I'll be ironing them out now

Alright the code works. It works pretty well. As said before, it is a small mineshaft program for early game designed to draw very little fuel. You can get it here: http://pastebin.com/Snm9QRNW
apemanzilla #4
Posted 17 April 2014 - 04:19 PM
Also, could you use proper indenting please? :)/>

You don't "step" it for each line, you increase the indentation once for each code chunk - like an if, or while, or function definition:

function hi()
  print("hi there!")
  if goodbye then
	print("goodbye :'(")
  end
  return
end
while true do
  hi()
end
Edited on 17 April 2014 - 02:19 PM
Zatilla7 #5
Posted 17 April 2014 - 07:16 PM
I'll work on it
RoD #6
Posted 17 April 2014 - 08:02 PM
Also, could you use proper indenting please? :)/>

You don't "step" it for each line, you increase the indentation once for each code chunk - like an if, or while, or function definition:

function hi()
  print("hi there!")
  if goodbye then
	print("goodbye :'(")
  end
  return
end
while true do
  hi()
end
And as i can see he uses spaces to do so :P/>
Try to press tab to ident your code correctly.
Dog #7
Posted 17 April 2014 - 08:22 PM
And as i can see he uses spaces to do so :P/>
Try to press tab to ident your code correctly.
So long as your 'tabs' aren't more than two spaces or so - anything more than that and the code becomes too expanded, imo. Personally, I prefer two spaces per indent, no tabs.
RoD #8
Posted 17 April 2014 - 08:45 PM
And as i can see he uses spaces to do so :P/>
Try to press tab to ident your code correctly.
So long as your 'tabs' aren't more than two spaces or so - anything more than that and the code becomes too expanded, imo. Personally, I prefer two spaces per indent, no tabs.
If you use a text editor like notepas++ its so easy cause its just *tab* to increase and *shift+tab* to decrease, its really fast and easy.
The cc editor also accepts tabs to ident (two space ident) but i dont know if it can decrease it.
Dog #9
Posted 17 April 2014 - 08:51 PM
And as i can see he uses spaces to do so :P/>
Try to press tab to ident your code correctly.

If you use a text editor like notepas++ its so easy cause its just *tab* to increase and *shift+tab* to decrease, its really fast and easy.
The cc editor also accepts tabs to ident (two space ident) but i dont know if it can decrease it.
I see what you're saying - you prefer to use the tab key for your indentation. Gotcha. I misunderstood.
Edited on 17 April 2014 - 06:52 PM