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

Attack and Spit

Started by hydranoid620, 30 January 2014 - 04:39 PM
hydranoid620 #1
Posted 30 January 2014 - 05:39 PM
I have a turtle that I want to attack then spit out any items that it has in its inventory. So far this is what I have in my program


theend = true
repeat
stuff
until theend == false
(Which I got from here: http://www.computerc...te-loop-in-lua/)

What can I do to make it so that it'll attack and spit out any items it gets into its inventory?
CometWolf #2
Posted 30 January 2014 - 06:13 PM
What you posted isn't an actual program, it's just an idea of how to do one.
This should be all you need
http://computercraft.info/wiki/Loops loops tutorial
http://computercraft.info/wiki/Turtle_Tutorial turtle tutorial
and the full turtle API http://computercraft.info/wiki/Turtle_%28API%29
TheOddByte #3
Posted 31 January 2014 - 08:15 AM
This is very easy to accomplish

--# Loop forever
while true do
   --# Loop until it doesn't detect anything infront of it
	while turtle.detect() do
		turtle.attack()
		for i = 1, 16 do
			turtle.select( i )
			turtle.drop()
		end
	end
	sleep( 0 )
end

Also, Check out the regular Lua page about loops and the turtle api page.
Edited on 31 January 2014 - 07:15 AM
Buho #4
Posted 04 February 2014 - 07:30 AM
Hellkid98's program should work, but the turtle will attack very slowly, since it takes time to empty out all 16 slots. With some experimentation on that program, you will be able to find out how to optimize it and speed it up. …Going so far as to fill the turtle's inventory with junk like stone swords so it can't pick up any loot, but then it's not technically "spitting".