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

Repeat

Started by itay51998, 08 September 2012 - 06:36 PM
itay51998 #1
Posted 08 September 2012 - 08:36 PM
Im trying to code mining turtle so it'll dig 6x6 area

repeat
turtle.digDown()
turtle.down()
turtle.digDown()
turtle.up()
turtle.forward()
until(6)


how i end the first reapet code and make it turn right and do the same??
(probbly easy to do but im new :/ )
sjele #2
Posted 08 September 2012 - 08:39 PM
Repeat works like this:


sPoint = 1 --Set it as one at the start
repeat
--Stuff
--Stuff
--We do often have a var the get increased in here or we use a function to retrive and number and store it
--In this example i'll use a var that increases:
sPoint = sPoint + 1 --We increase sPoint by 1
until sPoint == 10 --When sPoint reaches 10 it will end

Will try to look at code now


Code: i belive this works

Spoiler

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end
print("Done")
Lettuce #3
Posted 08 September 2012 - 08:43 PM
For this, instead of a repeat loop, try a for loop.

for i = 1,6 do
turtle.digDown()
turtle.down()
turtle.digDown()
turtle.up()
turtle.forward()
end

Then you can make the rest of the code, and after 6 iterations of this, it will do the rest of it.
itay51998 #4
Posted 08 September 2012 - 09:30 PM
Repeat works like this:


sPoint = 1 --Set it as one at the start
repeat
--Stuff
--Stuff
--We do often have a var the get increased in here or we use a function to retrive and number and store it
--In this example i'll use a var that increases:
sPoint = sPoint + 1 --We increase sPoint by 1
until sPoint == 10 --When sPoint reaches 10 it will end

Will try to look at code now


Code: i belive this works

Spoiler

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("right")

for i = 1, 6 do
turtle.digDown()
turtle.forward()
turtle.back()
turtle.turn("left")
end
print("Done")

when i tried that, it said: "bios206: [string "name"]:28: 'then' expected
Luanub #5
Posted 08 September 2012 - 09:35 PM
turtle.turn("left") is actually turtle.turnLeft(), and turtle.turn("right") is turtle.turnRight()
itay51998 #6
Posted 08 September 2012 - 10:01 PM
and after i make that work, how i detect if inventory is full and tell it go back and empty the inventroy?
Lettuce #7
Posted 08 September 2012 - 11:09 PM

if turtle.getItemCount(last free slot) >= 1 then
--do stuff
end
Just put in a slot that's the last free slot (for instance, if you have torches in slot 9, have it select 8) and then make the return program.
itay51998 #8
Posted 09 September 2012 - 06:42 PM
ok, thanks for all!