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

Big Reactors Program

Started by SullyPlayer, 08 November 2014 - 05:05 AM
SullyPlayer #1
Posted 08 November 2014 - 06:05 AM
So I'm making a program that emits a redstone signal when the reactor's energy in the big reactors mod is full, and stops that signal when it's not full.
I'm sort of new to ComputerCraft. I'm using what little knowledge I know and my Java knowledge.
Sorry to bother about this. I may see like an idiot, but I'd like to learn computercraft better.

p = peripheral.wrap("back")
while true do
if p.getEnergyStored() = 10000000
then
redstone set ("right") (true)
else
redsone set ("right") (false)
Bomb Bloke #2
Posted 08 November 2014 - 09:36 AM
You're structure's completely broken, but you've clearly got the idea as to how the logic of the script would work.

Here's a corrected version of your code:

local p = peripheral.wrap("back")

while true do
	if p.getEnergyStored() == 10000000 then
		rs.setOutput("right", true)
	else
		rs.setOutput("right", false)
	end
	
	-- Scripts must pause every now and then;
	-- ComputerCraft kills those that don't yield.
	sleep(5)
end

Though this block here:

	if p.getEnergyStored() == 10000000 then
		rs.setOutput("right", true)
	else
		rs.setOutput("right", false)
	end

… could be further shrunk:

	rs.setOutput("right", p.getEnergyStored() == 10000000)