Posted 20 November 2014 - 07:13 PM
Hello everyone.
I'm working on a project for a build of a rather large build. The project and program is set up to make sure that certain Thermal Expansion RF storage blocks don't drop below a specific value. I figured the hard part of this project was going to be learning how to wrap peripherals, but I'm not sure now I was right.
Code follows. The "Attempt to Index '?' a nil value" error hits at line 16… after allowing the same method to be called several times.
Pastebin: http://pastebin.com/Wt6QvEt2
Edit: I am chiefly confused by the several lines of identical code before :16: that work just fine.
I'm working on a project for a build of a rather large build. The project and program is set up to make sure that certain Thermal Expansion RF storage blocks don't drop below a specific value. I figured the hard part of this project was going to be learning how to wrap peripherals, but I'm not sure now I was right.
Code follows. The "Attempt to Index '?' a nil value" error hits at line 16… after allowing the same method to be called several times.
cellScience = peripheral.wrap("cofh_thermalexpansion_energycell_1")
cellIndustry = peripheral.wrap("cofh_thermalexpansion_energycell_2")
cellMENet = peripheral.wrap("cofh_thermalexpansion_energycell_3")
cellAgro = peripheral.wrap("cofh_thermalexpansion_energycell_4")
cellNuke = peripheral.wrap("cofh_thermalexpansion_energycell_5")
monitor = peripheral.wrap("monitor_1")
--The above block wraps all the relevant peripherals
--term.redirect(monitor) -- leashes everything to the monitor/commented out for testing
while true do
--These variables are in the loop to re-calculate on every pass.
maxScience = cellScience.getMaxEnergyStored("unknown")
maxIndustry = cellIndustry.getMaxEnergyStored("unknown")
maxMENet = cellMENet.getMaxEnergyStored("unknown")
maxAgro = cellAgro.getMaxEnergyStored("unknown")
maxNuke = cellNuke.getMaxEnergyStored("unknown")
capScience = cellScience.getEnergyStored("unknown")
capIndustry = cellIndustry.getEnergyStored("unknown")
capMENet = cellMENet.getEnergyStored("unknown")
capAgro = cellAgro.getEnergyStored("unknown")
capNuke = cellNuke.getEnergyStored("unknown")
monitor.clear()
term.setCursorPos(1, 1)
print("Testing Substation Charge:")
sleep(5)
--if derivations test each set. 5 total taking 5s each.
if capAgro/maxAgro > 3/4 then
print("Agricultural Substation Nominal")
else
print("Agricultural Substation Discharging")
end
sleep(5)
if capIndustry/maxIndustry > 3/4 then
print("Industrial Substation Nominal")
else
print("Industrial Substation Discharging")
end
sleep(5)
if capMENet/maxMENet > 3/4 then
print("M/E Network Substation Nominal")
else
print("M/E Network Substation Discharging")
end
sleep(5)
if capNuke/maxNuke > 3/4 then
print("Nuclear Facility Substation Nominal")
else
print("Nuclear Facility Substation Discharging")
end
sleep(5)
if capScience/maxScience > 3/4 then
print("Science Substation Nominal")
else
print("Science Substation Discharging")
end
print("Testing Complete.")
sleep(40) -- sum of sleep = 60 seconds
end --closes the loop
Pastebin: http://pastebin.com/Wt6QvEt2
Edit: I am chiefly confused by the several lines of identical code before :16: that work just fine.
Edited on 20 November 2014 - 08:42 PM