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

Override Function

Started by flaminsnowman99, 15 July 2012 - 12:08 AM
flaminsnowman99 #1
Posted 15 July 2012 - 02:08 AM
Is there a way to have a function that will override whatever you are doing at the time? So like if I have a reactor and it starts to overheat, is there a way to make it stop what you are doing and have a warning sign pop up?
Grim Reaper #2
Posted 15 July 2012 - 06:54 AM
Well, if your reactor program ran in a loop then you could check at the beginning of each loop for the specific condition (the temperature of the reactor being above a certain number) and then, if the conditions are true, then the loop can be broken by calling a warning function.

Do you have any code written that could help us help you a bit more specifically?
LucasUK #3
Posted 15 July 2012 - 02:31 PM
So could he have his reactor software running in the background and return the workstation to normal use mode. (But the reactor software is still monitoring!)
flaminsnowman99 #4
Posted 15 July 2012 - 04:58 PM
I tried to do an if statement at the beginning but it doesnt work. Heres some code.

while true do
term.clear()
term.setCursorPos(1,1)
print()
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
print("--------------------------------------")
print()
print("Welcome to SnowMan Headquarters")
print()
print("Reactor Mainframe")
print()
print("Please Choose An Action")
print("1. Reactor Menu")
print("2. Early Warning Signs")
print("3. Emergeny Shutdown")
print("4. Cooldown Settings")
print("5. Saftey Instructions")
bOut = colors.combine(bOut, colors.magenta)
rs.setBundledOutput("bottom", bOut)
e, p = os.pullEvent()
if rs.testBundledInput("bottom", colors.green) == true
  then heatMenu()
end
if rs.testBundledInput("bottom", colors.green) == false
  then heatMenu()
end
Thats the beginning of the code. Then heres the heatMenu its calling

local function heatMenu()
while true do
  os.pullEvent("redstone")
  mon = peripheral.wrap(right)
  if rs.testBundledInput("bottom", colors.green) then
   mon.clear()
   mon.setCursorPos(1,1)
   mon.write("Reactor State |>Normal<| Warm | Hot | Overheated")
  end
  if rs.testBundledInput("bottom", colors.yellow) then
   mon.clear()
   mon.setCursorPos(1,1)
   mon.write("Reactor State | Normal |>Warm<| Hot | Overheated")
  end
  if rs.testBundledInput("bottom", colors.orange) then
   mon.clear()
   mon.setCursorPos(1,1)
   mon.write("Reactor State | Normal | Warm |>Hot<| Overheated")
  end
  if rs.testBundledInput("bottom", colors.red) then
   mon.clear()
   mon.setCursorPos(1,1)
   mon.write("Reactor State | Normal | Warm | Hot |>Overheated<")
  end
end
end