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

Taking item from chest in for loop

Started by Anywen, 12 May 2015 - 12:58 PM
Anywen #1
Posted 12 May 2015 - 02:58 PM
Hello all, i've got a problem in one of my function. I'm trying to take item from a chest to the turtle.
For that, i've made a for loop that will inspect the 16 inventory slot and suck() item from the chest if needed.

Here is my code

function checkInventory()
for i=1,16,1 do
  turtle.select(i)
  if facing == NORTH and i < 4 then
   turtle.turnLeft()
   facing = facing + 3
  else if facing == WEST and i > 3 then
   turtle.turnRight()
   facing = facing - 3
  end
  if turtle.getItemCount() > 0 then
   inSlot = turtle.getItemDetail(i)
   print(inSlot.count)
   print(inSlot.name)
   if inSlot.name == "minecraft:wheat_seeds" and inSlot.count < 2 then
	print("sake a coke")
	turtle.suck()
   elseif inSlot.name == "minecraft:wheat" then
	local count = turtle.getItemCount()
	turtle.drop(count)
   elseif inSlot.name == "minecraft:wheat_seeds" and i > 3 then
	turtle.drop()
   end
  end  
end
end
end

The thing that i don't understand is that the turtle print my "sake a coke" but doesnt seem to pick items. Is the for loop executing too fast for the suck to be effective ?

Thank you in advance.
Anywen #2
Posted 12 May 2015 - 03:32 PM
Problem solved, i was having 2 error, one of my elseif was written "else if" and my facing was wrong.
KingofGamesYami #3
Posted 12 May 2015 - 03:33 PM
Is the turtle's face towards the chest? turtle.suck yields within itself, so it's impossible to execute too fast without the use of coroutines (parallel uses coroutines). I don't see any of that here, so it can't be that.

It's almost certain turtle.suck() is being executed, but is it being executed in the correct direction?
Lupus590 #4
Posted 12 May 2015 - 03:34 PM
line 7, you have a space in your else if