Jump to content




ShaftminerV2


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

#1 Rewok

  • Members
  • 93 posts

Posted 16 April 2014 - 08: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

#2 Exerro

  • Members
  • 801 posts

Posted 16 April 2014 - 10: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 by awsumben13, 16 April 2014 - 10:08 PM.


#3 Rewok

  • Members
  • 93 posts

Posted 17 April 2014 - 09: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

#4 apemanzilla

  • Members
  • 1,421 posts

Posted 17 April 2014 - 03: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 by apemanzilla, 17 April 2014 - 03:19 PM.


#5 Rewok

  • Members
  • 93 posts

Posted 17 April 2014 - 06:16 PM

I'll work on it

#6 RoD

  • Members
  • 313 posts

Posted 17 April 2014 - 07:02 PM

View Postapemanzilla, on 17 April 2014 - 03:19 PM, said:

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.

#7 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 17 April 2014 - 07:22 PM

View PostRoD, on 17 April 2014 - 07:02 PM, said:

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.

#8 RoD

  • Members
  • 313 posts

Posted 17 April 2014 - 07:45 PM

View PostDog, on 17 April 2014 - 07:22 PM, said:

View PostRoD, on 17 April 2014 - 07:02 PM, said:

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.

#9 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 17 April 2014 - 07:51 PM

View PostRoD, on 17 April 2014 - 07:45 PM, said:

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 by Dog, 17 April 2014 - 07:52 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users