Posted 26 October 2013 - 11:23 AM
[OpenCCsensors] reading Size from Inventory sensor
Application:
Im going to quickly describe what I am trying to do as there may be a better way than my code. Im using pulverizes to crush cobble to sand and using redstone engines to feed the cobble out of chests. The problem with this system is that eventually the redstone engines heat up and feed the cobble to fast causing the pulverizes to fill up even while operating at full power. My solution to this problem is to monitor the number of items inside the pulverizer and then set up a condition which will turn off and on the redstone engines accordingly. Bassically just keep the pulverizer stocked but not overflow allowing for the maximum efficiency. Right now i have to physically turn on and off a switch when the engines get to warm.
Problem:
The problem im having is getting the value in Size to store in a variable to be used in a condition. Here is the code i have so far.
I can use the sensorview program to view the targets, which there are about 4 or 5 of them since i have lots of chests, and other things in the vicinity. I place the sensor right next to the pulverizer and it is located at 0,0,-1. when i run the code above I get an error at line 5: attempt to call index ? (a nil value). I feel like im not populating info correctly or the Size parameter is missing. but im not sure to getTargetDetails for a specific target?
the rest of the code would be simple and something like this:
Thanks
Application:
Im going to quickly describe what I am trying to do as there may be a better way than my code. Im using pulverizes to crush cobble to sand and using redstone engines to feed the cobble out of chests. The problem with this system is that eventually the redstone engines heat up and feed the cobble to fast causing the pulverizes to fill up even while operating at full power. My solution to this problem is to monitor the number of items inside the pulverizer and then set up a condition which will turn off and on the redstone engines accordingly. Bassically just keep the pulverizer stocked but not overflow allowing for the maximum efficiency. Right now i have to physically turn on and off a switch when the engines get to warm.
Problem:
The problem im having is getting the value in Size to store in a variable to be used in a condition. Here is the code i have so far.
os.loadAPI("ocs/apis/sensor")
local mySensor = sensor.wrap("bottom")
local key = mySensor.getTargets()
local info = mysensor.getTargetDetails(key)
local size = info.Size
print(size)
I can use the sensorview program to view the targets, which there are about 4 or 5 of them since i have lots of chests, and other things in the vicinity. I place the sensor right next to the pulverizer and it is located at 0,0,-1. when i run the code above I get an error at line 5: attempt to call index ? (a nil value). I feel like im not populating info correctly or the Size parameter is missing. but im not sure to getTargetDetails for a specific target?
the rest of the code would be simple and something like this:
if size < 20 then
redstone.setOutput("right", true)
end
if size > 55 then
redstone.setOutput("right", false)
end
Thanks