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

reactor safety prpduce

Started by Britizz, 20 April 2018 - 09:12 AM
Britizz #1
Posted 20 April 2018 - 11:12 AM
hello,
i will soon go in the moon (with galacticraft of course) and i make a program for safety produce (without interuption).
there is the specifications :

when all reactors (two reactors) are down, one reactor are activated
when one reactor are down the other are activated.

but i can do that beacause my skils on conditional statments are limited
can you give me an advice or a program (thank's you very much if someone do that) for competing my program and terminate him (i will not leave on the moon until the program is ready).

thank's you
TheOddByte #2
Posted 20 April 2018 - 03:49 PM
I'm not 100% sure what you want, but is it this logic you mean?
Psuedo-code

--# This will store what reactor we're actively using
local index  = nil;

--# Wrap and store the reactors in a table since we'll use the variable above
--# to keep track of which one we're using
local reactors = {
	peripheral.wrap( "<name or side of reactor>" );
	peripheral.wrap( "<name or side of reactor>" );
}




--# Infinite loop
while true do

	--# If the index variable is nil we'll check if there is any reactor active
	--# and choose which one we'll keep track of
	if not index then

		--# We loop through all reactors and check if
		--# we find one that's already active
		for i, reactor in ipairs( reactors ) do
			if reactor.active() then
				index = i
				break
			end

			--# If we didn't find any active reactor then
			--# We'll choose the first one in the table to use
			if not index then
				index = 1
				reactors[index].activate() --# Here we activate it
			end
		end

	else

		--# If the reactor isn't active we'll activate another one
		--# so we'll increment the index variable with one to continue
		--# to the next reactor
		if not reactors[index].active() then
			index = index + 1 <= #reactors and index + 1 or 1
			reactors[index].activate()
		end
	end
    sleep( 0.5 )
end
Do take note that this is for the most part only a psuedo-code and I haven't checked what methods actually are available for the reactors in galacticacraft nor tested the code.
But from what I understood you only want one reactor active at a time?
Edited on 20 April 2018 - 01:50 PM
Britizz #3
Posted 20 April 2018 - 06:15 PM
yes that's it

EDIT : THANK'S YOU SO MUCH it's works (with correct function)
Edited on 20 April 2018 - 04:23 PM