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

Code not Looping

Started by LeaderKranz3, 05 January 2013 - 08:58 AM
LeaderKranz3 #1
Posted 05 January 2013 - 09:58 AM
I have looked into loops and tried using the While <condition> do and it did not work here is my code.


while turtle.detectFront=true do
turtle.dig()
end
while turtle.detectFront=false do
turtle.forward()
end
Luanub #2
Posted 05 January 2013 - 10:02 AM
turtle.detectFront is actually just turtle.detect() and it is a function call it needs () at the end and when you do comparisions its == to assign a value its = but to check bools you dont need the == just do this

while turtle.detect() do --while its true
  turtle.dig()
end
while not turtle.detect() do --while its false
  turtle.forward()
end
LeaderKranz3 #3
Posted 05 January 2013 - 10:11 AM
i got it mostly working now but when ever it mines a block it just stops and doesn't loop again



New Code:
while turtle.detect() do
turtle.dig()
end
while not turtle.detect() do
turtle.forward()
end
ChunLing #4
Posted 05 January 2013 - 10:18 AM
Of course, this is more useful if you are going to do things more than once, so:
while turtle.detect() do --while its true
  turtle.dig()
  turtle.digUp()
  turtle.forward()
end
This way we keep going forward as long as we find things to dig, and stop when we hit an empty space.

umm…be careful with this, it will dig itself into a wall and you might not be able to find it for a while.

Okay, now you should be able to follow it easily enough.
Edited on 05 January 2013 - 09:19 AM
LeaderKranz3 #5
Posted 05 January 2013 - 10:26 AM
Thank you for the help.
Loki #6
Posted 05 January 2013 - 10:39 AM
Maybe try learning a bit more on lua coding before you start trying to make turtle programs? Start with something simple. Learn how lua actually works a bit before moving onto CC :)/>.
ChunLing #7
Posted 05 January 2013 - 10:41 AM
Naw. I mean, you can do a lot of fun stuff in CC without knowing any programming at all. It's just that if you want to start making your own programs rather than relying on the default programs and whatever you can dredge out of the Programs/Turtle Programs forums, then you need to start learning Lua.