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

Attempt to compare __lt on nil and nil

Started by mattie078, 04 August 2015 - 04:44 PM
mattie078 #1
Posted 04 August 2015 - 06:44 PM
So I have this code:


os.loadAPI("ocs/apis/sensor")
local euSense = sensor.wrap("top")
while true do
	local total, totalCap = 0, 0
	for target in pairs(euSense.getTargets()) do
		local details = euSense.getTargetDetails(target)
print(details.Stored)
sleep(2)
eu = details.Stored
kappa = details.Capacity
if eu > kappa then
rs.setOutput("right", true)
sleep(10)
rs.setOutput("right", false)
else
rs.setOutput("right", false)
sleep(1)


end
end	  
end

Problem is it gives a error __lt on nil and nil (at line if eu > kappa then)
This is probally very noob but I'm not so really good in lua.
This is on Tekkit Lite using CCsensors
Edited on 04 August 2015 - 04:45 PM
Dragon53535 #2
Posted 04 August 2015 - 08:25 PM

for target in pairs(euSense.getTargets()) do
--#should probably be, 
for _,target in pairs(euSense.getTargets()) do
mattie078 #3
Posted 04 August 2015 - 09:36 PM

for target in pairs(euSense.getTargets()) do
--#should probably be,
for _,target in pairs(euSense.getTargets()) do

Got the same error with it
KingofGamesYami #4
Posted 04 August 2015 - 09:51 PM
does the print( details.Stored ) print 'nil'? The error is saying details.Stored and details.Capacity are both nil, I'd bet they should be details.stored and details.capacity. Capitalization matters!
Lyqyd #5
Posted 04 August 2015 - 10:45 PM

for target in pairs(euSense.getTargets()) do
--#should probably be, 
for _,target in pairs(euSense.getTargets()) do

That is not correct. The first line is right. The keys from the getTargets call's return value are passed as the argument to getTargetDetails.

OP, can you use the sensorview program and take a screenshot showing the information available on one of the targets you're trying to look at (run /ocs/programs/sensorview)?
Dragon53535 #6
Posted 04 August 2015 - 10:57 PM
Ahh, didn't know that, I assumed since details.Stored was nil, that details might of been an empty table returned because it couldn't find the target.
mattie078 #7
Posted 05 August 2015 - 12:13 PM
does the print( details.Stored ) print 'nil'? The error is saying details.Stored and details.Capacity are both nil, I'd bet they should be details.stored and details.capacity. Capitalization matters!

No they work with the capital.


for target in pairs(euSense.getTargets()) do
--#should probably be,
for _,target in pairs(euSense.getTargets()) do

That is not correct. The first line is right. The keys from the getTargets call's return value are passed as the argument to getTargetDetails.

OP, can you use the sensorview program and take a screenshot showing the information available on one of the targets you're trying to look at (run /ocs/programs/sensorview)?

Lyqyd #8
Posted 05 August 2015 - 07:45 PM
Do some of the other targets there not have the "Stored" key? You may just need to use an if statement around the lines that are trying to use the Stored and Capacity keys:


if details.Stored and details.Capacity then
  --code that uses the information.
end

Of course, if you're trying to look at just a single target, you don't need the loop at all. You could just use the coordinates to target the specific block you want information for.
mattie078 #9
Posted 06 August 2015 - 11:00 AM
Yes I want to target only the MFSU (2,-1,-1) how would I do that?

Ah got it, it got me thinking when you said if the able itself would have the Stored key. It is working fine now if only the MFSU is in the sensor range
Edited on 06 August 2015 - 09:57 AM
Lyqyd #10
Posted 06 August 2015 - 04:26 PM
You can get just the MFSU's information like this:


os.loadAPI("ocs/apis/sensor")
local euSense = sensor.wrap("top")

while true do
  local details = euSense.getTargetDetails("2,-1,-1")
  --do stuff with details.Stored and details.Capacity
  sleep(0.5)
end