Looking for some turtle programming help.

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

koeer11

New Member
Jul 29, 2019
98
0
0
So, what I want to happen is the turtles to kill monsters infront of it and drop the items either infront of them, or behind of them.
It would look like this

DTEETD
DTEETD

where
D = drop zone
T = turtle
E = empty

Currently I have this from the wiki that attacks when given a redstone current but doesnt get rid of the items.
while true do
while redstone.getInput("back") do
turtle.attack()
sleep(.1)
end
sleep(.5)
end
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
Is "empty" a chest? If so then you can use IIRC turtle.drop() to place the items in it. I'm not sure if turtle.drop() actually drops items in resource form though.
 

Fuzzlewhumper

New Member
Jul 29, 2019
500
0
0
while true do
---while redstone.getInput("back") do
------turtle.attack()
------sleep(.1)
------for i = 1, 8 do // go through the first 8 slots and drop anything in those slots to a chest below turtle.
---------turtle.select(i)
---------turtle.dropDown() // This could be turtle.dropUp() or turtle.drop() depending on where you want the turtle to drop stuff. If there isn't a chest, it will just shoot the items out in those directions.
------end
---end
---sleep(.5)
end

I think this would work... dashes in place of spaces for formatting appearance.
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
while true do
---while redstone.getInput("back") do
------turtle.attack()
------sleep(.1)
------for i = 1, 8 do // go through the first 8 slots and drop anything in those slots to a chest below turtle.
---------turtle.select(i)
---------turtle.dropDown()
------end
---end
---sleep(.5)
end

I think this would work... dashes in place of spaces for formatting appearance.

That's a lot of sleeping :p. You might want to use
Code:
os.queueEvent("")
coroutine.yield()
rather than
Code:
sleep(0.1)
it's so much faster and prevents 10 second termination as well as sleep().
 

ScottulusMaximus

New Member
Jul 29, 2019
1,533
-1
1
Turtles can't drop behind them only in front, down or up, if you want it to drop down use this:-

while true do
---while redstone.getInput("back") do
---turtle.attack()
---turtle.dropDown()
---sleep(0.2)
---end
sleep(.5)
end

If you want it to drop behind it the turtle will have to turn it so use this:-

while true do
---while redstone.getInput("back") do
---turtle.attack()
---turtle.turnLeft()
---turtle.turnLeft()
---turtle.drop()
---turtle.turnLeft()
---turtle.turnLeft()
---sleep(0.2)
---end
sleep(.5)
end

This'll only work if only the first slot is used otherwise you'll need the for loop Fuzzlewhumper(haha) has given you...

EDIT#1:- Formatting
EDIT#2:- for loop comment
 

DoctorOr

New Member
Jul 29, 2019
1,735
0
0
it's so much faster and prevents 10 second termination as well.

I have no idea where the idea that sleeping doesn't yield the process came from, but it's horribly wrong.

while(true) do
sleep (0.1)
end

will never terminate.
 

Symmetryc

New Member
Jul 29, 2019
317
0
0
I have no idea where the idea that sleeping doesn't yield the process came from, but it's horribly wrong.

while(true) do
sleep (0.1)
end

will never terminate.

I know...I was stated that my method was a faster alternative that could prevent it as well. Sorry if it was misworded