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

Redstone signal not emmiting

Started by HMJonesy, 07 September 2014 - 11:21 PM
HMJonesy #1
Posted 08 September 2014 - 01:21 AM
Here is the code ive been working on, it all works fine apart from redstone signal only emits if turbine 2 is offline and not when any of them go offline. could you please have a look and see what ive done wrong


local reactor1 = peripheral.wrap("BigReactors-Reactor_1")
local turbine1 = peripheral.wrap("BigReactors-Turbine_1")
local reactor2 = peripheral.wrap("BigReactors-Reactor_2")
local turbine2 = peripheral.wrap("BigReactors-Turbine_2")
local ec1 = peripheral.wrap("cofh_thermalexpansion_energycell_0")
local mon1 = peripheral.wrap("left")
local mon2 = peripheral.wrap("right")
while true do
sleep(0.5)
mon1.clear()
mon1.setTextScale(0.5)
mon2.clear()
mon2.setTextScale(0.5)

  mon1.setCursorPos(1,1)
  mon1.setTextColor(colors.white)
  mon1.write("Reactor: ")
  if reactor1.getActive (true) then
	mon1.setTextColor(colors.lime)
	mon1.write("Online")
	redstone.setOutput ("top",false)
	else
	mon1.setTextColor(colors.red)
	mon1.write("Offline")
	redstone.setOutput ("top",true)
  end

  mon1.setCursorPos(1,2)
  mon1.setTextColor(colors.white)
  mon1.write("Turbine: ")
  if turbine1.getActive (true) then
	mon1.setTextColor(colors.lime)
	mon1.write("Online")
	redstone.setOutput ("top",false)
  else
	mon1.setTextColor(colors.red)
	mon1.write("Offline")
	redstone.setOutput ("top",true)
  end	

  mon1.setCursorPos(1,4)
  mon1.setTextColor(colors.white)
  mon1.write("Power (RF/T): ")
  mon1.setTextColor(colors.lime)
  mon1.write(turbine1.getEnergyProducedLastTick())

  mon1.setCursorPos(1,5)
  mon1.setTextColor(colors.white)
  mon1.write("Stored RF: ")
  mon1.setTextColor(colors.lime)
  mon1.write(turbine1.getEnergyStored())

  mon1.setCursorPos(1,6)
  mon1.setTextColor(colors.white)
  mon1.write("Rotor Speed (RPM): ")
  mon1.setTextColor(colors.lime)
  mon1.write(turbine1.getRotorSpeed())

mon2.setCursorPos(1,1)
  mon2.setTextColor(colors.white)
  mon2.write("Reactor: ")
  if reactor2.getActive (true) then
	mon2.setTextColor(colors.lime)
	mon2.write("Online")
	redstone.setOutput ("top",false)
	else
	mon2.setTextColor(colors.red)
	mon2.write("Offline")
	redstone.setOutput ("top",true)
  end

  mon2.setCursorPos(1,2)
  mon2.setTextColor(colors.white)
  mon2.write("Turbine: ")
  if turbine2.getActive (true) then
	mon2.setTextColor(colors.lime)
	mon2.write("Online")
	redstone.setOutput ("top",false)
  else
	mon2.setTextColor(colors.red)
	mon2.write("Offline")
	redstone.setOutput ("top",true)
  end	

  mon2.setCursorPos(1,4)
  mon2.setTextColor(colors.white)
  mon2.write("Power (RF/T):")
  mon2.setTextColor(colors.lime)
  mon2.write(turbine2.getEnergyProducedLastTick())

  mon2.setCursorPos(1,5)
  mon2.setTextColor(colors.white)
  mon2.write("Stored RF: ")
  mon2.setTextColor(colors.lime)
  mon2.write(turbine2.getEnergyStored())

  mon2.setCursorPos(1,6)
  mon2.setTextColor(colors.white)
  mon2.write("Rotor Speed (RPM): ")
  mon2.setTextColor(colors.lime)
  mon2.write(turbine2.getRotorSpeed())

end
hilburn #2
Posted 08 September 2014 - 08:56 AM
it's not so much that it is only turning it on if turbine 2 is offline, it's that if reactor 2 is online, it turns the signal back off again when the code gets to there. There a couple of options to how you could fix this. but my suggestion would be to have 2 booleans, turbine1active and turbine2active which are set to true or false instead of the redstone output. then at the very end of the loop do something like:


if turbine1active or turbine2active then
	rs.setOutput("top",false)
else
	rs.setOutput("top", true)
end

Additionally, you could make your code much more compact if you used tables to store your peripherals, so instead of mon1, mon2 you have mon[1] and mon[2], that way you could just loop through your sensing/display code twice, with "for i=1,2 do"

hope this helps
Edited on 08 September 2014 - 06:57 AM
HMJonesy #3
Posted 08 September 2014 - 11:37 AM
this is my first ever code so will take me some time to work it out, but ill defo look into tables.

Cheers for the info