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

Melee Turtle programs

Started by PhilHibbs, 29 January 2013 - 03:07 AM
PhilHibbs #1
Posted 29 January 2013 - 04:07 AM
Has anyone done a program for a Melee Turtle? I've got a top-tier zombie spawner dropping into a 1x1 kill zone with a stone pressure plate to cut off the spawner and regulate the flow. All I need is a turtle that sits there and attacks, which I have, but it would be nice to be able to dump loot into a couple of chests (Rotten Flesh in one chest, all other loot in another). I'll have a go at it tonight if no-one's already done anything like this. At the moment my program is just this:


while 1 do
  if turtle.detect()
    turtle.attack()
  end
end

Should I introduce some kind of artificial delay such as sleep or yield in this to avoid CPU load?
Orwell #2
Posted 29 January 2013 - 04:49 AM
This is in the wrong section. Even though it's about programs, 'Ask a Pro' would be a better place to put this.

You're program has bad syntax, it's 'if turtle.detect() then'. But maybe you just mistyped. Besides that, I think that turtle.attack() does yield, so you don't have to put something else in there. (yielding isn't to avoid CPU load but to give other computers/programs a chance to run their code as well). Also, I don't believe that turtle.detect() returns true when the turtle has a mob in front of it (not 100% sure). You could really just have this:

while true do
  turtle.attack()
end
PhilHibbs #3
Posted 29 January 2013 - 05:39 AM
This is in the wrong section. Even though it's about programs, 'Ask a Pro' would be a better place to put this.

You're program has bad syntax, it's 'if turtle.detect() then'. But maybe you just mistyped. Besides that, I think that turtle.attack() does yield, so you don't have to put something else in there. (yielding isn't to avoid CPU load but to give other computers/programs a chance to run their code as well). Also, I don't believe that turtle.detect() returns true when the turtle has a mob in front of it (not 100% sure). You could really just have this:

while true do
  turtle.attack()
end

You're right that I missed out the "then", I'm not at the computer where my scripts are right now. I did find that adding a turtle.detect() check seemed to improve framerate in the game when there were no mobs in front of the turtle. Might have been an illusion, but it seemed better not to have the sword swinging when there's nothing there.
Orwell #4
Posted 29 January 2013 - 05:43 AM
This is in the wrong section. Even though it's about programs, 'Ask a Pro' would be a better place to put this.

You're program has bad syntax, it's 'if turtle.detect() then'. But maybe you just mistyped. Besides that, I think that turtle.attack() does yield, so you don't have to put something else in there. (yielding isn't to avoid CPU load but to give other computers/programs a chance to run their code as well). Also, I don't believe that turtle.detect() returns true when the turtle has a mob in front of it (not 100% sure). You could really just have this:

while true do
  turtle.attack()
end

You're right that I missed out the "then", I'm not at the computer where my scripts are right now. I did find that adding a turtle.detect() check seemed to improve framerate in the game when there were no mobs in front of the turtle. Might have been an illusion, but it seemed better not to have the sword swinging when there's nothing there.
It won't swing if there's nothing there; turtle.attack() returns false without swinging when there's no mob in range. As I said, I suspect that turtle.detect() doesn't even returns true when there's a mob in front of the turtle.
PhilHibbs #5
Posted 29 January 2013 - 06:51 AM
Odd. I'm sure saw it swinging away constantly with nothing there until I put in the detect check. I'll try again tonight.
Cranium #6
Posted 29 January 2013 - 07:50 AM
Moved to Ask a Pro.
Frederikam #7
Posted 29 January 2013 - 08:46 AM
To dump stuff down you can use:

turtle.dropDown()
Or in case you want it to drop forward:

turtle.drop()
Or have it drop the items up:

turtle.dropUp()
Putting one of these after turtle.attack() would be optimal.
Orwell #8
Posted 29 January 2013 - 09:05 AM
To dump stuff down you can use:

turtle.dropDown()
Or in case you want it to drop forward:

turtle.drop()
Or have it drop the items up:

turtle.dropUp()
Putting one of these after turtle.attack() would be optimal.
Optimal would be to dump the loot after the mob has been killed. Otherwise you'd kill the mob slower by dropping each item in between each blow.
PhilHibbs #9
Posted 29 January 2013 - 01:14 PM
I've made my script: http://www.computercraft.info/forums2/index.php?/topic/10013-melee-turtle-mob-farm-script/