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

turtle mob grinder

Started by tribalthomas, 14 February 2013 - 04:21 AM
tribalthomas #1
Posted 14 February 2013 - 05:21 AM
im making a mob grinder using turtles, but i cant get my program to work


while true do
turtle.attack()
sleep(2)
end

can anyone tell my what i did wrong
Sammich Lord #2
Posted 14 February 2013 - 05:23 AM
What error are you getting and are you using a melee turtle?
tribalthomas #3
Posted 14 February 2013 - 05:25 AM
im not getting a error the turtle just isnt attacking

yes im using a melee turtle
Kingdaro #4
Posted 14 February 2013 - 05:35 AM
The turtle only actually swings its sword if there's something to attack in front of it.
tribalthomas #5
Posted 14 February 2013 - 05:43 AM
i changed the code alittle

while true do
  while turtle.detectDown() = true do
    turtle.attack()
  end
end

now it says

[string "startup"]:2: 'do' expected

any ideas on how to fix it
Viproz #6
Posted 14 February 2013 - 07:03 AM
i changed the code alittle

while true do
  while turtle.detectDown() = true do
	turtle.attack()
  end
end

now it says

[string "startup"]:2: 'do' expected

any ideas on how to fix it

to compare two objects, you need to put "==" and not "=" so :

while true do
  while turtle.detectDown() == true do
	turtle.attack()
  end
end

But you don't need to put this, just do :

while true do
  while turtle.detectDown() do
	turtle.attack()
  end
end

Edit : the turtle.detectDown() func only return true when there is a block down
mrbaconbitts #7
Posted 14 February 2013 - 11:35 AM
All you need to have is


while true do
	 turtle.attack()
end

This will have your turtle attack only when there is a mob/person on the block directly in front of it. The sleep you have in your original code in unnecessary.
Skullblade #8
Posted 15 February 2013 - 01:39 AM
All you need to have is


while true do
	 turtle.attack()
end

This will have your turtle attack only when there is a mob/person on the block directly in front of it. The sleep you have in your original code in unnecessary.
U need the sleep or it will error
Doyle3694 #9
Posted 15 February 2013 - 01:40 AM
No it won't. Turtle functions yield.
theoriginalbit #10
Posted 15 February 2013 - 01:42 AM
No it won't. Turtle functions yield.
Only some turtle functions yield. but yes you are correct in this instance, this one yields.
Ninjarhh #11
Posted 15 February 2013 - 06:46 AM
In my opinion you should put a pressure plate infront on the turtle and do

while true do
    if redstone.getInput("front") then
	    turtle.attack()
    else
	    os.pullEvent("redstone")
    end
end
Viva la efficient coding ;P