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

[1.4.6] Another turtle API function + tweak to "refuel" program

Started by zeekkay, 11 January 2013 - 10:50 AM
zeekkay #1
Posted 11 January 2013 - 11:50 AM
turtle.getCurrentSlot() – Returns the integer of the turtle's current selected slot. (Seems useless at first glance, but it does have some use)

Tweak to "refuel" program:

– The template program "refuel" will now return the turtle to it's initial selected slot at program termination.

The reason for the second one is more of an annoyance. Personally I'm tired of fueling my turtle in creative, and then having to use lua to change the turtle's selected slot. I guess you could always make your program select the desired slot beforehand.
Cloudy #2
Posted 11 January 2013 - 12:04 PM
I guess you could always make your program select the desired slot beforehand.

That is exactly what you should do. It doesn't make sense if you don't.
Eric #3
Posted 11 January 2013 - 12:11 PM
turtle.getCurrentSlot()

Added in two lines of code:

local old = turtle.select
turtle.select = function(slot) turtle.slot = slot return old(slot) end

turtle.select(2)
print(turtle.slot)
immibis #4
Posted 11 January 2013 - 12:28 PM
I don't see why they don't add this to bios.lua:

local function wrap(fn)
  local value
  return function(...)
    local old = value
    value = ...
    fn(...)
    return old
  end
end
turtle.select = wrap(turtle.select)
term.setTextColor = wrap(term.setTextColor)
term.setBackgroundColor = wrap(term.setBackgroundColor)
but I'm sure they have their reasons. ("They" being cloudy and dan)
Sebra #5
Posted 12 January 2013 - 02:55 AM
Sorry, immibis, but such wraping would not work with term redirection.