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

Could I please get help with "for i = X, X do"

Started by Avous, 26 November 2012 - 06:57 AM
Avous #1
Posted 26 November 2012 - 07:57 AM
I'm trying to make a mining turtle clear a Eleven by Eleven area but I can't figure out how to redo sections of code a number of time.

http://pastebin.com/np68sbbb

There's the pastebin of my code, what am I doing wrong here? Could someone please help me out here?
Kingdaro #2
Posted 26 November 2012 - 08:10 AM
You really aren't doing anything wrong (minus the "end" on the last line that shouldn't be there), except digging in a spiral pattern is much more difficult than if you were digging in a zig-zag pattern.


local function digIfDetect()
	if turtle.detect() then turtle.dig() end
end

for i=1, 11 do
	for ii=1, 11 do
		digIfDetect()
		turtle.forward()
	end

	if i%2 == 0 then
		turtle.turnLeft()
		digIfDetect()
		turtle.forward()
		turtle.turnLeft()
	else
		turtle.turnRight()
		digIfDetect()
		turtle.forward()
		turtle.turnRight()
	end
end

The "digIfDetect()" part is only so that it doesn't try to dig empty blocks.
Avous #3
Posted 26 November 2012 - 08:18 AM
Thank you very much!

I'll edit it as per your suggestions and update this post with the details
Avous #4
Posted 26 November 2012 - 08:58 AM
Nevermind! i got it! thank you!