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

Need Help making code

Started by HightDetal, 18 June 2013 - 11:30 AM
HightDetal #1
Posted 18 June 2013 - 01:30 PM
i need to make code that would go like this
local x = turtle.getSlotNumber()+1
turtle.select(x)
Lyqyd #2
Posted 19 June 2013 - 10:52 AM
Split into new topic.

This can't be done. There is no way to get the number of the currently selected slot. You can instead use a variable to track which slot you selected last.


--at the top of the program:
local selection = 1
turtle.select(1)
local oldTurtleSelect = turtle.select
turtle.select = function(slot)
  if type(slot) ~= "number" then error("number expected, got "..type(slot)) end
  if slot < 1 or slot > 16 or math.floor(slot) ~= slot then error("bad argument") end
  selection = slot
  oldTurtleSelect(slot)
end
turtle.getSelect = function()
  return selection
end

--at the bottom:
turtle.getSelect = nil
turtle.select = oldTurtleSelect
HightDetal #3
Posted 20 June 2013 - 09:17 AM
Thanks