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

return currently selected slot number?

Started by CCJJSax, 28 March 2013 - 04:30 AM
CCJJSax #1
Posted 28 March 2013 - 05:30 AM
I made a slot selection program that uses arrows, and it tells you the currently selected slot, however, I don't know of any way I can do that without always starting from slot one every time it's ran.

so essentially I want to do something like "turtle.getselect()" and it returns with 5 if that's the slot selected. Is there a way to do that?
AnrDaemon #2
Posted 28 March 2013 - 06:07 AM
When I got struck by similar issue in position tracking, I went berserk and rewrote the API, adding all the missing code.
Lyqyd #3
Posted 28 March 2013 - 07:15 AM
You'll have to override the turtle.select function. Try putting this in startup:


local currentSelection = 1
local oldSelect = turtle.select
turtle.select = function(slot)
  if not slot then return currentSelection end
  if type(slot) ~= "number" then error("selection must be a number") end
  if slot < 1 or slot > 16 then error("slot number out of range") end
  local oldSelection = currentSelection
  if oldSelect(slot) then
    currentSelection = slot
  end
  return oldSelection
end