Jump to content




Patrol


2 replies to this topic

#1 MasterMinecraftCoder

  • New Members
  • 2 posts

Posted 13 October 2014 - 03: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

#2 Lemmmy

  • Members
  • 218 posts

Posted 18 October 2014 - 11:43 PM

yes thank you it works perfectly

#3 Xab

  • Members
  • 9 posts

Posted 19 October 2014 - 12: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users