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

Patrol

Started by MasterMinecraftCoder, 13 October 2014 - 02:07 AM
MasterMinecraftCoder #1
Posted 13 October 2014 - 04:07 AM
I have made a program that will protect you during night.

function Fuel()
turtle.select(1)
turtle.refuel(1)
end

function Move()
if turtle.getFuelLevel() < 10 then
Fuel()
end

turtle.forward()
turtle.attack()
turtle.forward()
turtle.attack()
turtle.forward()
turtle.attack()
turtle.forward()
turtle.attack()
turtle.forward()
turtle.attack()
turtle.forward()
turtle.attack()
turtle.turnRight()
turtle.turnRight()
end

while true do
Move()
end
Lemmmy #2
Posted 19 October 2014 - 12:43 AM
yes thank you it works perfectly
Xab #3
Posted 19 October 2014 - 01:52 AM
doing turtle.forward() turtle.attack() 6 times is the same as

for i=1,6 do
  turtle.forward()
  turtle.attack()
end
Which makes it easier to see what the code is doing and easier to configure. Say you wanted the turtle to patrol a 1000 square area, all you'd have to do is change the 6 to 1000. See if you can write code to allow the user to adjust the length of the patrol area.