Jump to content




Turtle drop help

turtle wireless

2 replies to this topic

#1 Obsidia

  • Members
  • 36 posts

Posted 18 September 2015 - 11:38 AM

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. :)

#2 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 18 September 2015 - 12: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


#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 19 September 2015 - 03: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 by HPWebcamAble, 19 September 2015 - 03:15 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users