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

need help with code....

Started by brokenmirror67, 24 October 2012 - 03:06 PM
brokenmirror67 #1
Posted 24 October 2012 - 05:06 PM
1- is there any way to make the turtle place blocks?
2- if there is how can i fill in a large floor with wood?
billysback #2
Posted 24 October 2012 - 05:18 PM
1: http://computercraft...itle=Turtle_api
2:

local left = true
for y=1,maxy do
   local x = 0
   while x <= maxx do
		while turtle.detect() do turtle.dig() sleep(0) end
		turtle.place()
		turtle.forwards()
   end
   if left then
	   left = false
	   turtle.turnLeft()
	   while turtle.detect() do turtle.dig() sleep(0) end
	   if not turtle.detect() then turtle.forwards() end
	   turtle.turnLeft()
   else
	   left = true
	   turtle.turnRight()
	   while turtle.detect() do turtle.dig() sleep(0) end
	   if not turtle.detect() then turtle.forwards() end
	   turtle.turnRight()
   end
end
^^^Untested^^^
You really should look around the forums however, this is both in the wrong place and the information you asked for is almost certainly in the forums somewhere.
Ditto8353 #3
Posted 24 October 2012 - 05:22 PM
Should put things like this in the "Ask a Pro" board
ChunLing #4
Posted 24 October 2012 - 08:31 PM
No, this is more "read the API description and the forum rules first." Ask a pro is for after you've done both of those.
Heracles421 #5
Posted 24 October 2012 - 08:39 PM
Guys, calm down and don't rage.

And broken, read the rules before posting a new thread, and do some research before too
ChunLing #6
Posted 25 October 2012 - 12:24 AM
Oh, com'on, you've seen us rage and this is not it. We can be really bad when we get mad.
slay_mithos #7
Posted 25 October 2012 - 09:22 PM
1: http://computercraft...itle=Turtle_api
2:

local left = true
for y=1,maxy do
   local x = 0
   while x <= maxx do
		while turtle.detect() do turtle.dig() sleep(0) end
		turtle.place()
		turtle.forwards()
   end
   if left then
	   left = false
	   turtle.turnLeft()
	   while turtle.detect() do turtle.dig() sleep(0) end
	   if not turtle.detect() then turtle.forwards() end
	   turtle.turnLeft()
   else
	   left = true
	   turtle.turnRight()
	   while turtle.detect() do turtle.dig() sleep(0) end
	   if not turtle.detect() then turtle.forwards() end
	   turtle.turnRight()
   end
end
^^^Untested^^^
You really should look around the forums however, this is both in the wrong place and the information you asked for is almost certainly in the forums somewhere.

I might be stupid, or blind, but your while seems to be an infinite loop.
For that kind of loops, you usually go for a FOR loop, as you don't have to remember to increment the variable, even more with lua not supporting the "x+=1"

Well, at least the guy asked, even if he would have had his answers in the tutorial of the wiki.
ChunLing #8
Posted 26 October 2012 - 02:23 AM
See, much more rage-like.
billysback #9
Posted 27 October 2012 - 09:53 AM
woops, forgot x = x + 1
and using a while loop at that point worked just as well and made it a little bit simpler, if I was writing that in Notepad I probably would have used a for loop but I was sort of just writing it simply as an example of what could be done in the post box…