35 posts
Posted 31 May 2013 - 10:37 PM
I want to read no joke 100 mfsu and display current power over max.
is there a way to read them all at once or do i need to write a program that takes the current value for each mfsu current power assign it to a variable then add them all up.
8543 posts
Posted 31 May 2013 - 11:14 PM
local euSense = sensor.wrap("top") --# change to sensor side.
while true do
local total, totalCap = 0, 0
for target in pairs(euSense.getTargets()) do
if target.Capacity == 10000000 then
total = total + target.Stored
totalCap = totalCap + target.Capacity
end
end
print(total.." / "..totalCap)
sleep(0.5)
end
If you want it to only do it once, take out the very last end, the while true do, and the sleep.
7083 posts
Location
Tasmania (AU)
Posted 31 May 2013 - 11:15 PM
Methinks 100 MFSUs might be overkill, yes? An
Adjustable Energy Storage Unit holds 10x what they do, while a
Inter-Dimensional Storage Unit stores 100x.
35 posts
Posted 31 May 2013 - 11:45 PM
local euSense = sensor.wrap("top") --# change to sensor side.
while true do
local total, totalCap = 0, 0
for target in pairs(euSense.getTargets()) do
if target.Capacity == 10000000 then
total = total + target.Stored
totalCap = totalCap + target.Capacity
end
end
print(total.." / "..totalCap)
sleep(0.5)
end
If you want it to only do it once, take out the very last end, the while true do, and the sleep.
i get an error. startup:1: attempt to index ? (a nil value) and yes my sensor is on top
130 posts
Posted 31 May 2013 - 11:48 PM
You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap
35 posts
Posted 31 May 2013 - 11:50 PM
You need to add os.loadAPI('ocs/apis/sensor') above the sensor.wrap
/facepalm
35 posts
Posted 31 May 2013 - 11:53 PM
local euSense = sensor.wrap("top") --# change to sensor side.
while true do
local total, totalCap = 0, 0
for target in pairs(euSense.getTargets()) do
if target.Capacity == 10000000 then
total = total + target.Stored
totalCap = totalCap + target.Capacity
end
end
print(total.." / "..totalCap)
sleep(0.5)
end
If you want it to only do it once, take out the very last end, the while true do, and the sleep.
all you get its a loop of 0/0
8543 posts
Posted 01 June 2013 - 02:54 AM
That's because I did it wrong! Give this a shot:
os.loadAPI("ocs/apis/sensor")
local euSense = sensor.wrap("top") --# change to sensor side.
while true do
local total, totalCap = 0, 0
for target in pairs(euSense.getTargets()) do
local details = euSense.getTargetDetails(target)
if details.Capacity == 10000000 then
total = total + details.Stored
totalCap = totalCap + details.Capacity
end
end
print(total.." / "..totalCap)
sleep(0.5)
end