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

Nuclear Reactor "OS" command help

Started by Cranium, 22 July 2012 - 12:23 AM
Cranium #1
Posted 22 July 2012 - 02:23 AM
I have been writing this code all day, and squashing bugs like it's a Whack-A-Mole game, but I had not hooked up my program to my reactor for fear that I would destroy EVERYTHING. now when it comes time to test the hardware after the software has been mostly pinned down, I find that none of my bundled cable outputs actually do anything. I thought I had the right codes for setting the output, and then turning them off, but apparently not…

-- screen functions
function newpage(rstat,cstat)
  term.setCursorPos(1,1)
  term.clearLine()
  term.setCursorPos(1,1)
  print("-------------------------------------------------")
  term.setCursorPos(1,2)
  term.clearLine()
  print("-			  Welcome to NukeOS			    -")
  term.setCursorPos(1,3)
  term.clearLine()
  print("-				  Ver. 1.0					 -")
  term.setCursorPos(1,4)
  term.clearLine()
  print("-------------------------------------------------")
  term.setCursorPos(1,5)
  term.clearLine()
  term.setCursorPos(1,6)
  term.clearLine()
  term.setCursorPos(1,7)
  term.clearLine()
  term.setCursorPos(1,8)
  term.clearLine()
  term.setCursorPos(1,9)
  term.clearLine()
  term.setCursorPos(1,10)
  term.clearLine()
  term.setCursorPos(1,11)
  term.clearLine()
  term.setCursorPos(1,12)
  term.clearLine()
  term.setCursorPos(1,13)
  term.clearLine()
  term.setCursorPos(1,14)
  term.clearLine()
  term.setCursorPos(1,15)
  term.clearLine()
  term.setCursorPos(1,16)
  print("Coolant Status:")
  term.setCursorPos(1,17)
  print("Reactor Status:")
  term.setCursorPos(1,5)
end
-- end screen functions
-- action functions                                             -- I thought that all of these functions would command it to
function rcon()                                                  -- turn the outputs on/off when ever they are called to later in the code.
  rs.setBundledOutput("back",colors.red)         -- But so far, the cables have not been outputting ANY signal!
end                                                                   -- Did I do something wrong?
function rcoff()
  rs.setBundledOutput("back", colors.subtract(colors.red))
end
function coolon()
  rs.setBundledOutput("back",colors.blue) 
end
function cooloff()
  rs.setBundledOutput("back",colors.subtract(colors.red))
end
-- end action functions
-- var
-- end vars
newpage()
  print("			 Please enter Password			   ")
term.setCursorPos(1,11)
write("PASSWORD:")
while true do
  correctpass = "redvsblue"
  password = io.read()
  if password == (correctpass) then
	 while true do
	    newpage()
		   
		  print("Please Select Function:")
		  print("1. Start Reactor")
		  print("2. Shutdown Reactor")
		  print("3. Logoff")
		  term.setCursorPos(1,10)
		  write("Selection:")
	    local menuinput = io.read()
	    if menuinput == "1" then
			    print("Reactor Starting...")
				 sleep(2)
				 print("Starting Coolant System...")
			    coolon()
				 sleep(2)
				 term.setCursorPos(1,16)
				 term.clearLine()
				 print("Coolant Status: On ")
				 term.setCursorPos(1,13)
				 print("Initiating Nuclear Reaction...")
			    rcon()
				 sleep(2)
				 term.setCursorPos(1,17)
				 term.clearLine()
				 print("Reactor Status: On ")
			    term.setCursorPos(1,14)
			    term.clearLine()
			    print("Reactor is now Online")
				 sleep(2)
	    elseif menuinput == "2" then
			    print("Reactor Shutting Off")
				 sleep(2)
			    print("Halting Nuclear Reaction...")
			    rcoff()
				 term.setCursorPos(1,17)
				 term.clearLine()
				 print("Reactor Status: Off")
			    term.setCursorPos(1,13)
				 sleep(2)
			    print("Shutting Down Coolant Flow...")
			    cooloff()
				 sleep(2)
				 term.setCursorPos(1,16)
				 term.clearLine()
				 print("Coolant Status: Off")
			    term.setCursorPos(1,14)
			    print("Reactor is now Off")
				 sleep(2)
	    elseif menuinput == "3" then
			    print("Thank you for using NukeOS")
			    print("The Reactor will now shut down")
			    print("Goodbye")
			    sleep(2)
			    os.reboot()			 
	    else
			    print("Incorrect command. Try Again.")
			    sleep(2)
	    end
	 end
  else
   print("INCORRECT PASSWORD")
   print("Please try again.")
    sleep(1)
    term.setCursorPos(10,11)
  end
end

Tagged is where I think the problem lies, be even after setting the first line of the code to set the bundled output to white just to test, the white cable did bupkiss. I am at a total loss as to what I did wrong.
Lyqyd #2
Posted 22 July 2012 - 02:40 AM
I haven't looked through the rest of the code, but this is probably what you wanted those to actually do:


function rcon()
  rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.red))
end
function rcoff()
  rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.red))
end
function coolon()
  rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.blue))
end
function cooloff()
  rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.blue))
end
Cranium #3
Posted 22 July 2012 - 04:23 AM
I replaced the code with what you had, but there was no noticeable change… I even added those commands in directly into the areas, but it did not put out a signal on either one.
Lyqyd #4
Posted 22 July 2012 - 04:33 AM
Make sure you have the cable correctly attached to the computer.
Cranium #5
Posted 22 July 2012 - 04:42 AM
I found out that the bundled cable must terminate at the computer, not run over the back. Thanks for the help!
Grim Reaper #6
Posted 22 July 2012 - 08:22 AM
I understand that the problem you were having has been solved, however I'd like to bring something in your program to your attention as well:

You clear each line with two different statements:

term.setCursorPos( args )
term.clearLine()

This takes up a large amount of space in your program and looks hideous! :)/>/>

A much smaller way of doing this is to write a loop that will use its iterator as the 'y' argument in term.setCursorPos( x, y )

Try this:

for i=1, 18 do
  term.setCursorPos( 1, i )
  term.clearLine()
end
-- Printing logic goes here

Hope I helped! :o/>/>
Cranium #7
Posted 22 July 2012 - 03:46 PM
well, the reason i did that is because since the reactor status is inside the function n tewpage(), it would clear out the lines down below everytime it cleared the page. i had previously had it start with clear(), but that would not keep the previous on/off status. if what you have there does that, then i would love to replace it. because yeah, that section looks hideous just to save that previous state of lines 16 and 17.
Grim Reaper #8
Posted 22 July 2012 - 10:15 PM
well, the reason i did that is because since the reactor status is inside the function n tewpage(), it would clear out the lines down below everytime it cleared the page. i had previously had it start with clear(), but that would not keep the previous on/off status. if what you have there does that, then i would love to replace it. because yeah, that section looks hideous just to save that previous state of lines 16 and 17.


for i=1, 18 do
  term.setCursorPos( 1, i )
  if i ~= 16 or i ~= 17 then term.clearLine() end
end
-- Printing logic goes here

This will check if the iterator is equal to 16 or 17 and then skip the clearLine() if it is equal to either value.

Hope I helped! :)/>/>
Cranium #9
Posted 23 July 2012 - 06:55 PM
Yes, it did help!
At least it DID, until I tried to separate the menus into different program files…(Totally my fault, not your code there)
So I ended up actually adding a new function to detect the current output of the cables, then turning that to a string, and then printing that string on the lower left. I then punctuated each sub-menu with that "newmenu()" function. But you definitely helped out with what I had before I screwed it all up!
Darky_Alan #10
Posted 24 July 2012 - 10:45 AM
I understand that the problem you were having has been solved, however I'd like to bring something in your program to your attention as well:

You clear each line with two different statements:

term.setCursorPos( args )
term.clearLine()

This takes up a large amount of space in your program and looks hideous! :)/>/>

A much smaller way of doing this is to write a loop that will use its iterator as the 'y' argument in term.setCursorPos( x, y )

Try this:

for i=1, 18 do
  term.setCursorPos( 1, i )
  term.clearLine()
end
-- Printing logic goes here

Hope I helped! :o/>/>

Or you know.. shell.run("clear")
Grim Reaper #11
Posted 24 July 2012 - 08:20 PM
I understand that the problem you were having has been solved, however I'd like to bring something in your program to your attention as well:

You clear each line with two different statements:

term.setCursorPos( args )
term.clearLine()

This takes up a large amount of space in your program and looks hideous! :)/>/>

A much smaller way of doing this is to write a loop that will use its iterator as the 'y' argument in term.setCursorPos( x, y )

Try this:

for i=1, 18 do
  term.setCursorPos( 1, i )
  term.clearLine()
end
-- Printing logic goes here

Hope I helped! :o/>/>

Or you know.. shell.run("clear")

He was trying to clear only certain lines to prevent having to rewrite certain information to the screen. If you look at the earlier posts I suggested something similar to which he declined and stated:

well, the reason i did that is because since the reactor status is inside the function n tewpage(), it would clear out the lines down below everytime it cleared the page. i had previously had it start with clear(), but that would not keep the previous on/off status. if what you have there does that, then i would love to replace it. because yeah, that section looks hideous just to save that previous state of lines 16 and 17.
Cranium #12
Posted 25 July 2012 - 12:10 AM
Yeah, finally got that section of my master control working like I want it. Here's what I have now:

-- screen functions
function newpage()
  term.clear()
  term.setCursorPos(1,1)
  print("-------------------------------------------------")
  print("-			  Welcome to NukeOS			    -")
  print("-				  Ver. 1.5					 -")
  print("-------------------------------------------------")
  term.setCursorPos(1,16)
  write("Coolant Status:")
  coolstat()
  term.setCursorPos(1,17)
  write("Reactor Status:")
  rcstat()
  term.setCursorPos(1,5)
end
function newmenu()
  newpage()
  term.setCursorPos(1,5)
  print("			 Please Select Function")
  term.setCursorPos(1,7)
  print("1. Start Reactor")
  print("2. Shutdown Reactor")
  print("3. Logoff")
  term.setCursorPos(1,11)
  write("Selection: ")
end
-- end screen functions
-- action functions
function rcon()
  rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.red))
end
function rcoff()
  rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.red))
end
function coolon()
  rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.blue))
end
function cooloff()
  rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.blue))
end
function coolstat() -- status of the coolant system (EE ice production and timer set to pulse a filter into the reactor really fast.)
if (colors.test(rs.getBundledOutput("back"), colors.blue)) == true then
   write(" Off")
elseif (colors.test(rs.getBundledOutput("back"), colors.blue)) == false then
   write(" On")
else
   write(" Unknown")
end
end
function rcstat() -- status of the reactor as it currently is.
if (colors.test(rs.getBundledOutput("back"), colors.red)) == true then
   write(" Off")
elseif (colors.test(rs.getBundledOutput("back"), colors.red)) == false then
   write(" On")
else
   write(" Unknown")
end
end
-- end action functions
-- var
-- end vars
cooloff()
rcoff()
newmenu()
while true do
local menuinput = io.read()
  if menuinput == "1" then
	    term.setCursorPos(1,12)
		 print("Reactor Starting...")
		  sleep(2)
		 print("Starting Coolant System...")
		 coolon()
	    term.setCursorPos(1,16)
		 print("Coolant Status: On ")
		  sleep(2)
	    term.setCursorPos(1,13)
	    term.clearLine(1,13)
		 print("Initiating Nuclear Reaction...")
		 rcon()
	    term.setCursorPos(1,17)
		 print("Reactor Status: On ")
		  sleep(2)
	    term.setCursorPos(1,14)
		 print("Reactor is now Online")
		  sleep(2)
		 newmenu()
  elseif menuinput == "2" then
	    term.setCursorPos(1,12)
	    print("Reactor Shutting Off")
		 sleep(1)
	    print("Halting Nuclear Reaction...")
	    rcoff()
	    term.setCursorPos(1,17)
	    print("Reactor Status: Off")
	    term.setCursorPos(1,13)
		 sleep(2)
	    print("Shutting Down Coolant Flow...")
	    cooloff()
	    term.setCursorPos(1,16)
		 print("Coolant Status: Off")
		 sleep(2)
	    term.setCursorPos(1,14)
		 print("Reactor is now Off")
		  sleep(2)
	    newmenu()
  elseif menuinput == "3" then
	    term.clear()
	    newpage()
	    term.setCursorPos(1,9)
	    print("Thank you for using NukeOS")
		 sleep(1)
	    print("The Reactor will now shut down for safety reasons.")
		 sleep(1)
	    term.clear()
	    term.setCursorPos(1,10)
	    print("				    Goodbye")
		 sleep(2)
	    os.reboot()			 
  else
	    print("Invalid command. Try Again.")
		 sleep(2)
	    newmenu()
  end
end

It took me a while to learn how to set the reactor status down there, but I'm pleased with it so far. Any suggestions would be appreciated!