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

Need help for turtle patrol.

Started by AncientMaster, 18 April 2013 - 06:09 PM
AncientMaster #1
Posted 18 April 2013 - 08:09 PM
I need help and been watching tutorials on ComputerCraft turtles and still can not get make the turtle patrol and if comes across any mob or person you attack. My idea is to add that if you have little fence to load fuel to a chest. and if you have a full inventory fence to download. Using a point source and a chest. The chest and the chest would be under the charge q would be left if anyone has an idea I would like to know.

But what interests me patrol and kill the bug that crosses think the event turtle.detect () not be used either. at the moment I'm using the sentinel turtle q is:

while true do
turtle.attack ()
end

this'm using. I would like to know if anyone knows how I can make patrol. and try the turtle.forward () does not work -. -

would greatly appreciate assistance.
unobtanium #2
Posted 19 April 2013 - 12:16 AM
I really dont understand what you want…

The only thing i can imagine is, that you want the turtle to protect you while it is moving around, hitting what is in the way.
turtle.forward() does work. I think you have to check out LUA and the turtle api once more, because you made some basic mistakes with the ( You should check if the turtle has fuel to be able to move.

An idea (!) how i would do it. Change it for your personal usage:


while true do
for i=1,10 do
  while not turtle.forward() do
   turtle.attack()
   sleep(0.2)
 end
end
turtle.turnLeft()
turtle.turnLeft()
end
This lets the turtle patrol 10 blocks back and forth all day long. If it cant move forward - a mob is in the way - the turtle starts attacking it until the turtle can move forward. That's it.


PS: You wrote in the wrong forum. This here is the forum for finished programs. For questions go to Ask A Pro
theoriginalbit #3
Posted 19 April 2013 - 12:52 AM
Wow that was a massive fail for Google Translate, well I hope it's Google Translate!

To expand on UNOBTANIUMS code (I would personally do this)

while true do
  for i = 1, 10 do
	if not turtle.forward() then
	  if turtle.attack() then
		while turtle.attack() do end -- something is in the way, player/mob
	  elseif turtle.detect() then
		-- ? well there is a block in the way, handle that problem in some way, maybe dig it?
	  elseif turtle.getFuelLevel() == 0 then
		-- refuel it in some way
	  end
  end
  turtle.turnLeft()
  turtle.turnLeft()
end

-snip-
You are missing an 'end' and also the space in between the function name and the () is not a mistake, it can be done, its an advantage of programming languages that don't care about white space.
unobtanium #4
Posted 19 April 2013 - 01:51 AM
Wanted to go as deep into it allready^^ I like yours more then mine :P/>

Yeah, i hate this code frame. It is so unhandy…
Didnt know about the dont-have-to-make-() rule, but i cant see any real positiv aspect by doing it.
theoriginalbit #5
Posted 19 April 2013 - 01:55 AM
Didnt know about the dont-have-to-make-() rule, but i cant see any real positiv aspect by doing it.
Spaces in the name matter. just before the () that doesn't
Cranium #6
Posted 19 April 2013 - 01:59 AM
Moved to Ask a Pro. Questions about your own code, and issues with your own code go in this section.