1 posts
Location
Mississippi
Posted 01 July 2015 - 10:37 PM
I swear this code is perfect and I have no idea what else to do, so here I am.
Code is as follows:
local reactor = peripheral.wrap("left")
while true do
sleep(0)
if reactor.getEnergyStored() < 1000000 then
reactor.setActive (true)
end
if reactor.getEnergyStored() > 10000000 then
reactor.setActive (false)
end
end
8543 posts
Posted 02 July 2015 - 01:05 AM
Moved to Ask a Pro.
957 posts
Location
Web Development
Posted 02 July 2015 - 01:38 AM
It would really help to know what the exact error is, since it has the line number
But without the line…
Is there actually a reactor to the left of the computer?
I think you need to use the Reactor Computer Port to interface with the reactor in any way, is the computer touching that?
Side notes:
Use code tages [code.] code here without the period
Instead of sleep(0), why not sleep(5), or higher? Does it really need to run every few ticks?
Here is the code, cleaned up a bit:
Spoiler
local reactor = peripheral.wrap("left")
while true do
if reactor.getEnergyStored() < 1000000 then
reactor.setActive(true)
else --# If the energey isn't less than 1000000, then it must be greater
reactor.setActive(false)
end
sleep(5)
end
Edited on 01 July 2015 - 11:41 PM
7083 posts
Location
Tasmania (AU)
Posted 02 July 2015 - 02:51 AM
--# If the energey isn't less than 1000000, then it must be greater
Not so - it could be equal! :P/> Though that's still, of course, a better way to do it.
Another option is to forget about the "if" block, simply resolving the check and passing the result directly to reactor.setActive():
reactor.setActive(reactor.getEnergyStored() < 1000000)