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

Countdown Program for Nuclear Reactor

Started by schwatzgelb89, 26 September 2014 - 10:10 AM
schwatzgelb89 #1
Posted 26 September 2014 - 12:10 PM
Hey Guys,


I need a program that I can control my reactor. It should run automatically a certain time and then turn off. In addition, it should automatically perform an emergency shutdown when a redstone signal comes from the left. I have written a program, but unfortunately it does not work. I hope you can help me.

Many thanks!

Here is the code:


local monitor = peripheral.wrap("top")
monitor.clear()
monitor.setTextScale(1.5)
monitor.setCursorPos(2,3)
monitor.write("<Reaktor 1 AKTIV>")
monitor.setCursoPos(4,3)
monitor.write("Automatische Abschaltung in:")
monitor.setCursorPos(6,3)
redstone.setOutput("right", true)
monitor.write("3:00")
sleep(1)
for minutes = 2, 0, -1 do
for seconds = 59, 0, -1 do
monitor.clear()
monitor.setCursorPos(2,3)
monitor.write("<Reaktor 1 AKTIV>")
monitor.setCursoPos(4,3)
monitor.write("Automatische Abschaltung in:")
monitor.setCursorPos(6,3)
monitor.write((minutes < 10 and "0"..minutes or minutes)..":"..(seconds < 10 and "0"..seconds or seconds))
sleep(1)
if redstone.getInput("left", true) then shell.run"Stoerfall"
end
end
redstone.setOutput("right", false)

monitor.clear()
monitor.setCursorPos(6,3)
monitor.write("00:00")
sleep(5)
monitor.clear()
monitor.setCursorPos(2,3)
monitor.write("<Reaktor 1 wurde abgeschaltet>")
sleep(20)
os.reboot()
Simon #2
Posted 27 September 2014 - 04:11 AM
Change

if redstone.getInput("left", true) then shell.run"Stoerfall"
end
To:

if redstone.getInput("left", true) then shell.run("Stoerfall")
end

Is it not working aside from that?
Edited on 27 September 2014 - 02:12 AM
Dragon53535 #3
Posted 27 September 2014 - 04:24 AM
Besides what simon helped you with, what does it do that it shouldn't, what happens before it doesn't work, any information as to what the problem could be pointed towards?
KingofGamesYami #4
Posted 27 September 2014 - 04:46 AM
Here's my take on it:

local monitor = peripheral.wrap("top")
monitor.clear()
monitor.setTextScale(1.5)
monitor.setCursorPos(2,3)
monitor.write("<Reaktor 1 AKTIV>")
monitor.setCursoPos(4,3)
monitor.write("Automatische Abschaltung in:")
monitor.setCursorPos(6,3)
redstone.setOutput("right", true)
monitor.write("3:00")
sleep(1)
for minutes = 2, 0, -1 do --#unclosed for loop
  for seconds = 59, 0, -1 do
    monitor.clear()
    monitor.setCursorPos(2,3)
    monitor.write("<Reaktor 1 AKTIV>")
    monitor.setCursoPos(4,3)
    monitor.write("Automatische Abschaltung in:")
    monitor.setCursorPos(6,3)
    monitor.write((minutes < 10 and "0"..minutes or minutes)..":"..(seconds < 10 and "0"..seconds or seconds))
    sleep(1)
    if redstone.getInput("left", true) then --#rs.getInput accepts only a single parameter, thus true is unnecessary and ignored.
      shell.run"Stoerfall" --#shell.run has to be called using parentheses "()"
    end
  end
  redstone.setOutput("right", false)

  monitor.clear()
  monitor.setCursorPos(6,3)
  monitor.write("00:00")
  sleep(5)
  monitor.clear()
  monitor.setCursorPos(2,3)
  monitor.write("<Reaktor 1 wurde abgeschaltet>")
  sleep(20)
  os.reboot()

Just indenting the code properly reveals a great deal.