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

Parallel Functions

Started by JamesUK, 22 November 2013 - 03:34 AM
JamesUK #1
Posted 22 November 2013 - 04:34 AM
Hey guys's im new to computercraft and ive been playing around with for about 13 hours now, haven't slept.

So here is my problem if you guys can help, i'm trying to have a readout mointer that shows when my reactors are on or off and which also shows if the temperature is above 2000 which enables the controls rods. but i cant get both readouts on the screen at the same time.

local monitor = peripheral.wrap("left")
term.redirect(monitor)

function write()
print("Reactor Building One")
print()
end

local function reactorOneStatus()
  os.pullEvent("redstone")
  state = rs.testBundledInput("back", colors.white)
if state then
   term.setCursorPos(1,3)
   term.clearLine()
   print()
   print("Rector one : ON ")
  elseif not state then
   term.setCursorPos(1,3)
   term.clearLine()
   print()
   print("Rector one : OFF")
  end
end

local function reactorOneTempStatus()
print("test parallel")
  os.pullEvent("redstone")
  state = rs.testBundledInput("back", colors.white)
if state then
   term.setCursorPos(1,5)
   print()
   print("Rector Temp : fail safe")
  elseif not state then
   term.setCursorPos(1,5)
   print()
   print("Rector Temp : OK")
  end
end

write()

while true do
  parallel.waitForAny(reactorOneStatus, reactorOneTempStatus)
end

reactorOneStatus()
reactorOneTempStatus()
AgentE382 #2
Posted 22 November 2013 - 12:34 PM
First, you don't need to use two functions in parallel. Second, using functions in parallel messes around with event handling. I don't remember how. Third, you're testing the same condition in both tests. Let me illustrate this for you by rewriting your code:
print("Reactor Building One")
print()

os.pullEvent("redstone")
state = rs.testBundledInput("back", colors.white)

if state then
  term.setCursorPos(1,3)
  term.clearLine()
  print()
  print("Rector one : ON ")

  term.setCursorPos(1,5)
  print()
  print("Rector Temp : fail safe")
else
  term.setCursorPos(1,3)
  term.clearLine()
  print()
  print("Rector one : OFF")

  term.setCursorPos(1,5)
  print()
  print("Rector Temp : OK")
end
That should be equivalent to your code. If that's not what you want it to do, you should post what you do want it to do, so we can help you do it. :)/>
Edited on 22 November 2013 - 11:37 AM