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

Turtle drop help

Started by Obsidia, 18 September 2015 - 10:38 AM
Obsidia #1
Posted 18 September 2015 - 12:38 PM
Just a quick little question.
Basically I want the turtle to drop something out of a specific slot based on what I enter after the command… Like "Drop 3" and it drops the item in Slot 3, "Drop 2" and it drops the item in Slot 2.

Can anyone tell me how to do that?

thanks and have a nice day. :)/>
hbomb79 #2
Posted 18 September 2015 - 01:33 PM
I assume you know of the turtle.drop() command?

I see what your problem is, you could change the syntax to: "drop:3" then get the section before the colon (drop) and after(3). If the section before is drop then try to convert the post part (3) into a number, if it works drop the item


input = string.lower( read() )
if string.find( input, ":" ) then
local pre = string.sub( input, 1, string.find( input, ":" )-1 )
local post = string.sub( input, input:find( ":" )+1, input:len() )
if pre == "drop" and post then
  -- Wants to drop
  local temp = tonumber( post )
  if temp then
   turtle.drop( temp )
  else
   print("Invalid drop argument. drop:<slot>")
  end
else
  print("Unknown command")
end
end
HPWebcamAble #3
Posted 19 September 2015 - 04:13 PM
If your PROGRAM is named 'drop', then when you run it, then number would be argument.


--# In the program 'Drop'

local args = {...} --# Gets the arguments that the user passed when the program was run

turtle.select( tonumber( args[1] ) ) --# Selects the slot, denoted by the first argument
turtle.drop( 64 ) --# Drops the entire stack. You could also have the user specify how many to drop as a second argument

You will want to read up on tables a bit to use this method:
http://www.lua.org/pil/2.5.html
Edited on 19 September 2015 - 02:15 PM