Drop All But One Slot - Loop Not Working
#1
Posted 08 January 2013 - 06:10 PM
Im trying to code a little something that has a turtle drop everything in all slots except slot 1. To achieve this, I'm trying a for loop as so..
for i=2,9 do
turtle.select(i)
turtle.drop()
end
However, I have noticed that this procedure can be pretty random. Sometimes it will keep slot 1. Other times, it throws it away like everything else. Anyone have any suggestions for fixing this problem? Thank you!
#2
Posted 08 January 2013 - 06:13 PM
Secondly. That looks fine to me. Are you sure it isn't something somewhere else in the code? and is this copied from the code or retyped? if retyped, make sure it looks like this one.
#3
Posted 08 January 2013 - 08:44 PM
#4
Posted 08 January 2013 - 09:24 PM
#5
Posted 08 January 2013 - 11:39 PM
Really, the most likely candidate I can think of for the described behavior is that the drop and select commands are accidentally transposed in the actual code, like:
for i=2,9 do turtle.drop() turtle.select(i) endOkay, I can think of something likelier I bet...how about that the 2 is being passed as a variable, and it isn't really always two?
Now I'm just making while guesses, though.
#6
Posted 08 January 2013 - 11:43 PM
ChunLing, on 08 January 2013 - 11:39 PM, said:
Given scope its the only issue I could think of, hence the questions. But I don't see many people trying to do this
2 = 16I think common sense should kick in there with most people...
#7
Posted 09 January 2013 - 12:20 AM
If we go on the theory that the code as posted is acting as described because of something somewhere else, then the likely culprit would be a redefinition of the turtle API functions. Not because that's even remotely likely, but because there's nothing else I can see there that could have been redefined elsewhere in a way that would affect the loop as described.
#8
Posted 09 January 2013 - 04:08 PM
function digLine(blocks)
for i = 1,blocks-1 do
if turtle.getItemCount(9) ~= 0 then
dropoff()
end
while forward() == false do
turtle.dig()
end
end
end
function dropoff()
recordCoord = {current[1],current[2],current[3]}
recordCompass = compass
goToDest(origin)
dropAndReset()
end
function dropAndReset()
goToDest(dropZone)
while compass ~= originalCompass do
turnLeft()
end
for i = 2,9 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
goToDest(origin)
end
It's weird in that sometimes it will drop slot 1 and sometimes not. Even wierder, it will follow the correct sequence (dropping 2 first, then 3, 4..) until the end when it randomly drops slot 1. I am playing on a server, so could it be the lag perhaps? Again, thank you guys very much and I hope I gave enough information
#9
Posted 09 January 2013 - 04:42 PM
Could you try putting a sleep(3) statement
for i = 2,9 do turtle.select(i) turtle.drop() end sleep(3) --Here turtle.select(1) goToDest(origin)Other than that, I have no idea...
#10
Posted 09 January 2013 - 05:27 PM
#11
Posted 10 January 2013 - 03:50 AM
marth010, on 09 January 2013 - 05:27 PM, said:
Well, maybe it's your goToDest() that has something weird, because if the turtle drops the slot 1 when traveling, it probably has to do with goToDest().
Just to make sure, try changing the loop a bit like this:
slot = 2 for i = 1,8 do turtle.select(slot) turtle.drop() slot = slot + 1 end
Shouldn't do much difference between using i, but just in case
#12
Posted 10 January 2013 - 04:04 AM
Heracles421, on 10 January 2013 - 03:50 AM, said:
marth010, on 09 January 2013 - 05:27 PM, said:
Well, maybe it's your goToDest() that has something weird, because if the turtle drops the slot 1 when traveling, it probably has to do with goToDest().
Just to make sure, try changing the loop a bit like this:
slot = 2 for i = 1,8 do turtle.select(slot) turtle.drop() select = select + 1 end
Shouldn't do much difference between using i, but just in case
Why are you incrementing select?
#13
Posted 10 January 2013 - 05:08 AM
remiX, on 10 January 2013 - 04:04 AM, said:
Heracles421, on 10 January 2013 - 03:50 AM, said:
marth010, on 09 January 2013 - 05:27 PM, said:
Well, maybe it's your goToDest() that has something weird, because if the turtle drops the slot 1 when traveling, it probably has to do with goToDest().
Just to make sure, try changing the loop a bit like this:
slot = 2 for i = 1,8 do turtle.select(slot) turtle.drop() select = select + 1 end
Shouldn't do much difference between using i, but just in case
Why are you incrementing select?
Fixed
#14
Posted 10 January 2013 - 08:57 AM
#15
Posted 11 January 2013 - 02:51 PM
if turtle.getItemCount(1) >= 0 then
print("I have them")
else
print("I dropped them")
end
However, even when the turtle would randomly drop the first slot, it would claim to still have them.. Idk. This is weird. I have the entire program if anyone would want to see it and possibly help me with what's happening. Thanks again you guys for the responces and feedback
#16
Posted 11 January 2013 - 02:57 PM
Also, upload your entire program to pastebin or something so we can take a look at it, run it for ourselves, etc.
#17
Posted 11 January 2013 - 03:10 PM
(btw I've never used pastebin before and I'm not even sure if that's the right website lulz)
#18
Posted 11 January 2013 - 04:08 PM
#19
Posted 11 January 2013 - 04:32 PM
#20
Posted 11 January 2013 - 04:35 PM
marth010, on 11 January 2013 - 04:32 PM, said:
you could always do this
turtle.select( 1 ) turtle.drop( turtle.getItemCount( 1 ) - 1 )This would drop all except for 1
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











