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

[Question][Lua] Need help with openCCsensors

Started by CubeCat, 19 February 2013 - 02:26 AM
CubeCat #1
Posted 19 February 2013 - 03:26 AM
Title: [Question][Lua] Need help with openCCsensors

Need a simple example program wich can count items in inventory and compare with variable and if true - redstone signal. Just cant find any of openCCtutorials or videos with simple code and functions…

BTW: Sorry for my English, thanks in advance.
Mikeemoo #2
Posted 19 February 2013 - 08:59 AM


os.loadAPI("ocs/apis/sensor")
local invent = sensor.wrap("left")
local target = "1,0,0"
local signalAt = 10
local outputSide = "back"
while true do
  local details = invent.getTargetDetails(target)
  local count = 0
  for key, slot in pairs(details.Slots) do
    count = count + slot.Size
  end
  rs.setOutput(outputSide, count >= signalAt)
  sleep(2)
end

Every 2 seconds this will check the chest at "targetAt", and if there's the same amount (or more) of "signalAt", it'll output a redstone signal on "outputSide"
CubeCat #3
Posted 19 February 2013 - 10:09 AM


os.loadAPI("ocs/apis/sensor")
local invent = sensor.wrap("left")
local target = "1,0,0"
local signalAt = 10
local outputSide = "back"
while true do
  local details = invent.getTargetDetails(target)
  local count = 0
  for key, slot in pairs(details.Slots) do
	count = count + slot.Size
  end
  rs.setOutput(outputSide, count >= signalAt)
  sleep(2)
end

Every 2 seconds this will check the chest at "targetAt", and if there's the same amount (or more) of "signalAt", it'll output a redstone signal on "outputSide"

Tnx a lot!
Mikeemoo #4
Posted 19 February 2013 - 12:03 PM
No worries