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

program monitoring power levels in a Big Reactors reactor

Started by sir_buttocks, 16 March 2014 - 08:53 PM
sir_buttocks #1
Posted 16 March 2014 - 09:53 PM
Hi!

I just started with computercraft and have been trying to make a program that activates/deactivates a Big Reactor depending in its level of power stored.

I dont know how to keep the program looping and get around the "peripheral :62: Too long without yielding", but here is what i have so far:




local reactor

reactor = peripheral.wrap("back")

reactor.getEnergyStored()

while reactor.getEnergyStored() < 9900000

do reactor.setActive (true)

end

while reactor.getEnergyStored() > 9900000

do reactor.setActive (false)

end
adencraft2000 #2
Posted 16 March 2014 - 10:31 PM
Does this work for you?

local reactor = peripheral.wrap("back") -- Wrap the reactor to the back
while true do -- Loop forever
  sleep(0) -- This sleeps for 0 seconds, still casing a delay though
  if reactor.getEnergyStored() < 9900000 then -- If the reactor has less than 9900000 then
	reactor.setActive (true) -- Activate the reactor
  end
  if reactor.getEnergyStored() > 9900000 then -- If the reactor has more than 9900000 then
	reactor.setActive (false) -- Activate the reactor
  end
end
(http://pastebin.com/4xJF8fXU)
Not sure if you know but something that is useful with code is spacing.
When you have an "if", "while", "function" etc.. you indent the code from that by TWO (2) spaces each time
Examples:

if "test" == "test" then
  print("Test")
end

while true do
  print("Test")
end

function test()
  print("Test")
end

function test()
  if "test" == "test" then
    while true do
	  print("Test")
    end
  end
end
sir_buttocks #3
Posted 16 March 2014 - 11:02 PM
Its working! Thanks alot <3