Jump to content




More Efficient Way To Empty Inventory?

turtle

2 replies to this topic

#1 J-Nutz

  • Members
  • 14 posts

Posted 20 May 2014 - 02:30 PM

I am working on a felling program right now and was wondering if you had a simpler way of clearing the extra stuff in the inventory? Here's my code.

--[[
	 Background info
	 Saplings go in slot 1
	 Bonemeal goes in slot 2
	 Coal goes in slot 16
	 Trying to empty the wood it cuts and any extra
	 Saplings and Bonemeal
--]]

-- Empty Inventory

function emptyInventory()

for inv = 3, 15, 1 do
turtle.select(inv)
  if turtle.compareTo(1) == true then
   turtle.dropDown()
  elseif turtle.compareTo(2) == true then
   turtle.turnLeft()
   turtle.drop()
   turtle.turnRight()
  end
end

end

-- End Empty Inventory

Edited by J-Nutz, 20 May 2014 - 02:31 PM.


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 May 2014 - 02:40 PM

not overly... its a pretty standard code...

you could improve it in this way though
local function emptyInventory()
  turtle.turnLeft()
  for i = 3, 15 do
	turtle.select( i )
	if turtle.compareTo(1) then
	  turtle.dropDown()
	elseif turtle.compareTo(2) then
	  turtle.drop()
	end
  end
  turtle.turnRight()
end

as you can see there's just some minor improvements, such as removing the redundant == true check, and the possibility of the Turtle turning a lot.

Edited by theoriginalbit, 20 May 2014 - 02:41 PM.


#3 J-Nutz

  • Members
  • 14 posts

Posted 20 May 2014 - 02:57 PM

View Posttheoriginalbit, on 20 May 2014 - 02:40 PM, said:

not overly... its a pretty standard code...

you could improve it in this way though
local function emptyInventory()
  turtle.turnLeft()
  for i = 3, 15 do
	turtle.select( i )
	if turtle.compareTo(1) then
	  turtle.dropDown()
	elseif turtle.compareTo(2) then
	  turtle.drop()
	end
  end
  turtle.turnRight()
end

as you can see there's just some minor improvements, such as removing the redundant == true check, and the possibility of the Turtle turning a lot.

Ahh, Thanks for the tips. Being a first time Lua programmer, these little things help me learn early and keep me from making mistakes and keeping my code as simple as possible. :D

Can never remember the whole 'Local' thing.

Edited by J-Nutz, 20 May 2014 - 02:58 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users