28 posts
Posted 14 September 2013 - 01:06 AM
I have this simple piece of code that isnt doing anything… it just closes the program
it should detect a mob, then attack, then go through its inventory and drop everything
local x = turtle.detect()
while true do
if x == true then
turtle.attack()
turtle.attack()
for i = 1, 16 do
turtle.select(i)
turtle.drop()
end
end
end
799 posts
Location
Land of Meh
Posted 14 September 2013 - 03:08 AM
Firstly, you need the turtle.detect() inside the loop. Second, you need to have the loop wait for a bit every time it runs, otherwise it'll error (close the program).
while true do
if turtle.detect() then
turtle.attack()
turtle.attack()
for i = 1, 16 do
turtle.select(i)
turtle.drop()
end
end
sleep(0.5)
end
72 posts
Posted 14 September 2013 - 03:14 AM
You're suppose to put the error that you're getting. which in this case is "1: attempt to index ? (a nil value)" am I right? turtle.detect() doesn't detect mobs, only detects blocks in front of the turtle, so it doesn't need to be in the code cause it would only run if there was a block placed in front of it which is pointless.
while true do
turtle.attack()
turtle.attack()
for i = 1, 16 do
turtle.select(i)
turtle.drop()
end
sleep(0.5)
end
28 posts
Posted 14 September 2013 - 12:57 PM
You're suppose to put the error that you're getting. which in this case is "1: attempt to index ? (a nil value)" am I right? turtle.detect() doesn't detect mobs, only detects blocks in front of the turtle, so it doesn't need to be in the code cause it would only run if there was a block placed in front of it which is pointless.
while true do turtle.attack() turtle.attack() for i = 1, 16 do turtle.select(i) turtle.drop() end sleep(0.5) end
gravity score solved it for me… i didnt get an error code, and they are melee turtles… i dont think i would detect and attack with a mining turtle lol, and yes, when a melee turtle.detects it detects mobs, not blocks
799 posts
Location
Land of Meh
Posted 14 September 2013 - 02:17 PM
You're suppose to put the error that you're getting. which in this case is "1: attempt to index ? (a nil value)" am I right? turtle.detect() doesn't detect mobs, only detects blocks in front of the turtle, so it doesn't need to be in the code cause it would only run if there was a block placed in front of it which is pointless.
while true do
turtle.attack()
turtle.attack()
for i = 1, 16 do
turtle.select(i)
turtle.drop()
end
sleep(0.5)
end
When having a loop that never yields, sometimes (not sure under which circumstances) the computer will just shut down or the program will exit and not give an error message. Just because turtle.detect() might not detect mobs (which it does), calling it without a mob in front of the turtle won't cause an attempt to index nil - the function itself still exists (the error would occur if the function didn't exist), it'll just return false.
72 posts
Posted 14 September 2013 - 04:38 PM
When it comes from the turtle.detect() I pulled that info right from the wiki.
http://computercraft.info/wiki/Turtle_(API)If it does detect mobs the wiki needs to be updated for it.
1522 posts
Location
The Netherlands
Posted 14 September 2013 - 05:38 PM
When it comes from the turtle.detect() I pulled that info right from the wiki.
http://computercraft...ki/Turtle_(API)If it does detect mobs the wiki needs to be updated for it.
Turtles cannot detect mobs, just tested it to be very sure on this answer.
28 posts
Posted 15 September 2013 - 12:28 AM
When it comes from the turtle.detect() I pulled that info right from the wiki.
http://computercraft...ki/Turtle_(API)If it does detect mobs the wiki needs to be updated for it.
Turtles cannot detect mobs, just tested it to be very sure on this answer.
what kind of turtle did you use?
for me when i have a melee turtle, it does nothing, but if myself of a mob moves in front of it, it will 'activate'
72 posts
Posted 15 September 2013 - 01:13 AM
its because they will always attack, it just it won't do the animation unless there is something in front of it. I assume that is the mod itself and not part of lua.
28 posts
Posted 15 September 2013 - 01:33 AM
ok, im assuming the turtle can only detect 1 block in front of it? if so then it shouldnt activate unless if there is a block in front of it, correct?
115 posts
Posted 15 September 2013 - 02:44 AM
If you just use
turtle.detect()
then yes.
But you can also detect up and down, using
turtle.detectUp()
and
turtle.detectDown()
respectively
28 posts
Posted 15 September 2013 - 03:13 AM
If you just use
turtle.detect()
then yes.
But you can also detect up and down, using
turtle.detectUp()
and
turtle.detectDown()
respectively
yes, i know that, i mean it shouldnt even attack if a mob walks in front of it, but at least if its a melee turtle it will attack on the instance of detecting a mob
28 posts
Posted 15 September 2013 - 04:56 AM
also, will endermen attempt to tp if attacked by a turtle?
17 posts
Posted 16 September 2013 - 09:09 PM
[We already gave you your own post. Go read the sticky posts and then go find the split post. It'll be started by you, so check the topic listings. -L]
Edited on 16 September 2013 - 08:24 PM