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

Reactor Toggle Parellel Run?

Started by SNWLeader, 17 December 2014 - 01:42 AM
SNWLeader #1
Posted 17 December 2014 - 02:42 AM
I am using this code to have a panel that shows stats of the reactor that we need to know on a 3 x 3 monitor screen.

I need to get some way to have the computer realize when I press a certain key that it will toggle the reactor from on to off vice versa.

What would you recommend?

here is my code

reactor = "BigReactors-Reactor_23"
monitor = "monitor_27"
logo = "logo"
rmax = 9999999

l = paintutils.loadImage(logo)
r = peripheral.wrap(reactor)
m = peripheral.wrap(monitor)
amount = r.getEnergyStored()
active = r.getActive()
fuel = r.getFuelAmount()
fuelmax = r.getFuelAmountMax()
function printlogo(x,y)
paintutils.drawImage(l,x,y)
end

function resetcolors()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
end

function activetog()
if os.pullEvent("char") == "y" then
  if r.getActive() == true then
   r.setActive(false)
  elseif r.getActive() == false then
   r.setActive(true)
  end
end
end

function looprun()
while true do
amount = r.getEnergyStored()
percent = math.ceil((fuel / fuelmax) * 100)
term.redirect(m) --Sets functions to monitor.
term.clear()
if active == true then
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.green)
  write(" ")
elseif active == false then
   term.setcursorPos(1,1)
   term.setBackgroundColor(colors.red)
   write(" ")
end
printlogo(3,-1)
resetcolors()
term.setCursorPos(1,17)
term.setTextColor(colors.red)
write("Fuel: ")
term.setTextColor(colors.green)
write(fuel)
term.setCursorPos(15,17)
term.setTextColor(colors.red)
write("Percent: ")
term.setTextColor(colors.green)
write("%"..percent)
term.setCursorPos(1,18)
term.setTextColor(colors.red)
write("RF:")
term.setTextColor(colors.green)
write(amount)
term.setCursorPos(15,18)
term.setTextColor(colors.red)
write("Active: ")
term.setTextColor(colors.green)
write(tostring(active))
resetcolors()
term.current()
sleep(0.2)
end
end

looprun()
KingofGamesYami #2
Posted 17 December 2014 - 03:41 AM

function getKey()
  --#get key input, turn off reactor, etc.
end

parallel.waitForAny( looprun, getKey )

Edit: Fixed code tags.
Edited on 17 December 2014 - 02:42 AM
SNWLeader #3
Posted 17 December 2014 - 04:54 AM
Thanks man…. :D/> does exactly what I need.

function getKey()
  --#get key input, turn off reactor, etc.
end

parallel.waitForAny( looprun, getKey )

Edit: Fixed code tags.