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

BigReactors automation program issues

Started by StormWolf, 20 April 2018 - 09:18 AM
StormWolf #1
Posted 20 April 2018 - 11:18 AM
Hello, I'm pretty now to ComputerCraft so please excuse any dumb mistakes I make. I've been trying to expand upon a simple BigReactos script I found here that simply turns the reactor on when below a certain threshold then turns it back off once it reaches another, large threshold. Initially I wanted to set it up such that I had 3 different thresholds. One at a very low value that would go off and kick the reactor into high gear, another that would turn it down a bit once it had some buffer room in the internal RF storage and the final value it stays at until it fills at which point it turns off.

What I have here is a shell of that. My first question is if there is some screwy issue with BigReactors where it gives the internal readings of the RF levels wrong? It would repeatedly think that the interna; RF was above my second threshold, skipping the lowest internal level, highest level of power generation. I was forced to only create 3 conditions instead of 4 which was what I have below. If that was unclear I'm sorry, it's 3:30 AM and I've been working on this for hours. My more relevant question is trying to fix an issue with my current program where it's getting a "too long without yielding" error. I read around about "sleep" and someone suggested a fake "event call" both of which are seen below. Neither of which fixed the program. That is my more relevant question. Thanks in advance!


term.clear()
reactor = peripheral.wrap("BigReactors-Reactor_0")
term.setCursorPos(1,2)
write("----------Reactor Generation Status----------")

while true do
energy = reactor.getEnergyStored()

if energy < 10000000 then
	reactor.setActive (true)
	term.setCursorPos(1,1)
	term.clearLine()
	write("Energy buffer below 3,000,000, reactor active")
	if energy < 1000000 then
		reactor.setAllControlRodLevels(30)
		term.setCursorPos(1,3)
		term.clearLine()
		write("RF buffer low. Increasing power generation.")
		sleep(10)
		os.queueEvent("We Yield For No One!");
		os.pullEvent();
	end
	else
reactor.setAllControlRodLevels(80)
		term.setCursorPos(1,3)
		term.clearLine()
		write("RF buffer nominal. Setting normal power generation.")
		sleep(10)
		os.queueEvent("We Yield For No One!");
		os.pullEvent();
	end
end

if energy >= 10000000 then
  reactor.setActive (false)
  term.setCursorPos(1,1)
  term.clearLine()
  write("Energy buffer at 4 million, hibernating reactor")
  term.setCursorPos(1,3)
  term.clearLine()
  write("Reactor Inactive")
  sleep(10)
  os.queueEvent("We Yield For No One!");
  os.pullEvent();
end
Jummit #2
Posted 20 April 2018 - 03:10 PM
Does this work?

reactor = peripheral.wrap("BigReactors-Reactor_0")
I thought you have to specify the side of the peripheral, not the type.

For the too long without yielding error, you only call sleep and pull events if the energy is high, not in the main while loop. Moving it out of the if clause should solve it.

Also, you can use

if i>10 then
else
end
instead of

if i>10 then
end
if i<=10 then
end

I think you got this.

I think this is not right:

while true do
  energy = reactor.getEnergyStored()
  if energy < 10000000 then
	if energy < 1000000 then

	end
  else

  end
end

-- do you want this if clause in the main loop?
if energy >= 10000000 then

end
Edited on 20 April 2018 - 01:19 PM
Dog #3
Posted 20 April 2018 - 03:36 PM
Does this work?

reactor = peripheral.wrap("BigReactors-Reactor_0")
I thought you have to specify the side of the peripheral, not the type.

That's valid. When connecting a peripheral via modem/network-cable you use the peripheral name returned by the modem instead of the side (the peripheral name is shown on screen when you turn the modem on).

As Jummit stated, all your conditionals need to be within the main loop. I would suggest structuring it like so…

while true do
  if energy >= 10000000 then
	--# do high energy stuff here
  elseif energy < 10000 then
	--# do low energy stuff here
  else
	--# do medium energy stuff here
  end
  sleep(5) --# sleep at the end of the loop - no need to put sleeps in each if statement
end

Also, either use sleeps or use the queue event/pull event method to avoid yielding errors, but don't use both - either one is sufficient - I recommend sleeps. If you prefer to use queue/pull then you'll wan't your os.pullEvent calls to also filter for the same event that you queued (in this case "We Yield For No One!")
Edited on 20 April 2018 - 01:38 PM