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

Reactor reboot problem

Started by Xixili, 23 April 2014 - 08:41 PM
Xixili #1
Posted 23 April 2014 - 10:41 PM
Hello everyone,

Im using computercraft to control my nuclear reactor.
Everything works fine except one thing.
Turning off the reactor and rebooting the computer doesnt work.

at line 30 I added this code:

  elseif green == "true" then
	os.reboot()

But it seems not working and im struggling with this for several days now.
Maybe somebody knows the answer.

Full code below:


mon = peripheral.wrap("left")
rednet.open("top")
mon = peripheral.wrap("left")
mon.setBackgroundColor(colors.black)
green = rs.testBundledInput("back", colors.green)	-- SHUTDOWN CONSOLE
temp = 1
reactor = "Querying"
maxHeat = 1
output = "Querying"
timeLeft = "Querying"
tempPercent = "Querying"
adjustTemp = 5000
x,y = mon.getSize()
rednet.broadcast("ping")
reactorCom = 358  -- reactor computer ID
maxStorageL = "1"
energyL = "1"
nir = 313 -- Nuclear information reader ID


function display()
  mon.setTextColor(colours.black)
  if reactor == "false" then
	mon.setBackgroundColor(colors.red)
	rectr = "OFF"
  elseif reactor == "true" then
	mon.setBackgroundColor(colors.lime)
	rectr = "ON"
  elseif green == "true" then
	os.reboot()
  else
	rectr = "QRY"
	mon.setBackgroundColor(colors.orange)
  end
  p = 1
  for i = 1,3 do
	mon.setCursorPos(x-5, p)
	mon.write("	 ")
	p = p + 1
  end
	p = 0
	mon.setCursorPos(x-4, 2)
	mon.write(rectr)
	mon.setBackgroundColor(colours.black)
	mon.setTextColor(colors.white)
	mon.setCursorPos(x/3+1, y-2)
	mon.write("Reactor Temp: "..tempPercent.."%")
	mon.setCursorPos(1, y-1)
mon.setBackgroundColor(colours.black)
	mon.setTextColor(colors.green)
	mon.write("0%")
	mon.setCursorPos(x/2, y-1)
mon.setBackgroundColor(colours.black)
	mon.setTextColor(colors.orange)
	mon.write("50%")
	mon.setCursorPos(x-3, y-1)
mon.setBackgroundColor(colours.black)
	mon.setTextColor(colors.red)
	mon.write("100%")
	if tempPercent == "Querying" --[[or tempPercent == 0 ]] then
	  mon.setCursorPos(1, y)
	  mon.write("Temprature Unknown... Querying")
	elseif tempPercent/2 < 1 then
	  mon.setCursorPos(1, y)
	  mon.setBackgroundColor(colors.lime)
	  mon.write(" ")
	  mon.setBackgroundColor(colors.black)
	  else
	  for i = 1, tempPercent, 2 do
		p = p + 1
		mon.setCursorPos(p,y)
		if p < x/4 then
		mon.setBackgroundColor(colors.lime)
		mon.write(" ")
		mon.setBackgroundColor(colors.black)
		elseif p < x/2 then
		mon.setBackgroundColor(colors.green)
		mon.write(" ")
		mon.setBackgroundColor(colors.black)
		elseif p < x/4*3 then
		mon.setBackgroundColor(colors.orange)
		mon.write(" ")
		mon.setBackgroundColor(colors.black)
		elseif p <= x then
		mon.setBackgroundColor(colors.red)
		mon.write(" ")
		mon.setBackgroundColor(colors.black)
		end
	  end
	  p = 0
  end
end


local result
result = fs.exists("shutTemp")
if result == true then
  file = io.open("shutTemp", "r")
  shutTemp = file:read()
  file:close()
elseif result == false then
  shutTemp = 1000
end

local result
result = fs.exists("rctrStatus")
if result == true then
  file = io.open("rctrStatus", "r")
  reactor = file:read()
  file:close()
  if reactor == "true" then
	rednet.send(reactorCom, "on")
  elseif reactor == "false" then
	rednet.send(reactorCom, "off")
  end
elseif result == false then
  rednet.send(reactorCom, "off")
end
while true do
  display()
  event, param1, param2, param3 = os.pullEvent()
  if event == "rednet_message" then
	if param2 == "heat" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  temp = b
	elseif param2  == "reactorPoweredB" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  reactor = tostring(B)/>/>/>
	  file = fs.open("rctrStatus", "w")
	  file.write(B)/>/>/>
	  file:close()
	elseif param2  == "maxHeat" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  maxHeat = b
	elseif param2 == "output" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  output = b
	elseif param2 == "timeLeft" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  timeLeft = b --*0.00277778
	elseif param2 == "energyL" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  energyL = b
	  energyL = tonumber(energyL)
	  if energyL > 10000000 then
		energyL = 10000000
	  end
	elseif param2 == "maxStorageL" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  maxStorageL = b
	elseif param2 == "isSteam" then
	  rednet.send(nir, "ping")
	  a,b = rednet.receive(.5)
	  isSteam = b	
	end
	mon.clear()
	mon.setCursorPos(1,1)
	mon.setTextColor(colors.white)
	if reactor == "true" then
	  mon.write("Reactor 1: ")
	  mon.setTextColor(colors.lime)
	  mon.write("ON")
	  mon.setTextColor(colors.white)
	elseif reactor == "false" then
	  mon.write("Reactor 1: ")
	  mon.setTextColor(colors.red)
	  mon.write("OFF")
	  mon.setTextColor(colors.white)
	else
	  mon.write("Reactor 1: "..reactor)
	end
	mon.setCursorPos(1,3)
	tempPercent = temp / maxHeat
	tempPercent = tempPercent*100
	tempPercent = math.floor(tempPercent)
	mon.write("Reactor Temp: "..temp.."c")
	mon.setCursorPos(1,5)
	mon.write("EU Output: "..output)
	mon.setCursorPos(1,7)
	mon.write("Fuel: "..timeLeft)
	mon.setCursorPos(1,9)
	mon.write("Shutdown Temp: "..shutTemp)
	mon.setCursorPos(21, 1)
	mfsuE = tonumber(energyL)
	mfsuEL = tonumber(maxStorageL)
	if mfsuE == mfsuEL then
	  mon.write("MFSU: 100%")
	else
	  mfsuPercent = mfsuE / mfsuEL
	  mfsuPercent = mfsuPercent*100
	  mfsuPercent = math.floor(mfsuPercent)
	  mon.write("MFSU: "..mfsuPercent.."%")
	end
--	mon.setCursorPos(21, 3)
--	mon.write("EU: "..mfsuE)
  elseif event == "monitor_touch" then
	if param2 > x-6 and param3 < 4 then
	  if reactor == "false" then
		rednet.send(reactorCom, "on")
	  elseif reactor == "true" then
		rednet.send(reactorCom, "off")
	  end
	  j,k = rednet.receive()
	  if j == reactorCom and k == "false" then
		for i = 1,4 do
		mon.setBackgroundColor(colors.red)
		mon.clear()
		mon.setTextScale(4)
		mon.setTextColor(colors.black)
		mon.setCursorPos(1, 2)
		mon.write("OVERHEATING!")
		os.sleep(.5)
		mon.clear()
		mon.setTextColor(colors.red)
		mon.setBackgroundColor(colors.black)
		mon.setCursorPos(1, 2)
		mon.write("OVERHEATING!")
		os.sleep(.5)
		end
	  end
	  mon.setTextScale(1)
	  mon.setBackgroundColor(colors.black)
	  mon.setTextColor(colors.lime)
	  rednet.broadcast("ping")
	elseif param3 == y then --and param2 * 2 * 100 < 7500 then
	  adjustTemp = param2 * 2 * 100
		mon.setCursorPos(param2, param3)
		mon.setBackgroundColor(1)
		mon.write(" ")
		mon.setBackgroundColor(colors.black)
	  rednet.send(reactorCom, "maxTemp")
	  id, message = rednet.receive()
	  if id == reactorCom then
		adjustTemp = tostring(adjustTemp)
		rednet.send(reactorCom, adjustTemp)
		id, message = rednet.receive()
		if message == "true" and id == reactorCom then
		  shutTemp = adjustTemp
		  file = fs.open("shutTemp", "w")
		  file.write(shutTemp)
		  file:close()
		elseif message == "false" and id == reactorCom then
		  mon.setCursorPos(1,y)
		  for i = 1,x do
			mon.write(" ")
		  end
		  mon.setCursorPos(1,y)
		  mon.write("Max Temp Failed To Update!")
		end
	  end
	end
  end
end
Edited on 23 April 2014 - 08:42 PM
CometWolf #2
Posted 23 April 2014 - 10:49 PM

green = rs.testBundledInput("back", colors.green)
will return

true
not

"true"
see where im going with this?

  elseif green == "true" then
A boolean and a string are not the same.
Xixili #3
Posted 23 April 2014 - 10:55 PM

green = rs.testBundledInput("back", colors.green)
will return

true
not

"true"
see where im going with this?

  elseif green == "true" then
A boolean and a string are not the same.
I tried both and none worked sadly
CometWolf #4
Posted 23 April 2014 - 10:59 PM
It's also worth pointing out that you aren't updating your variable, so unless the green input is on when you start the program, it will never read as true either.
Xixili #5
Posted 23 April 2014 - 11:00 PM
It's also worth pointing out that you aren't updating your variable, so unless the green input is on when you start the program, it will never read as true either.
Then how do I make the computer to read it?
CometWolf #6
Posted 23 April 2014 - 11:08 PM
What im saying is, you are storing the result of this

rs.testBundledInput("back", colors.green)
in the variable green, at the start of your program. Beyond that point, you don't appear to modify the variable, so it will always retain it's inital value. I'd suggest making use of the redstone event to trigger rechecks of your redstone state.
Edited on 23 April 2014 - 09:08 PM
Xixili #7
Posted 24 April 2014 - 04:39 PM
What im saying is, you are storing the result of this

rs.testBundledInput("back", colors.green)
in the variable green, at the start of your program. Beyond that point, you don't appear to modify the variable, so it will always retain it's inital value. I'd suggest making use of the redstone event to trigger rechecks of your redstone state.
I guess that im thinking too difficult.

I added this code:

  if green == true then
	os.reboot()
  else
	rs.setBundledOutput("back", colours.blue)
end
blue cable responds but reboot doesnt.
and adding os.pullEvent("redstone") doesnt work either.
Edited on 24 April 2014 - 02:40 PM
CometWolf #8
Posted 24 April 2014 - 06:23 PM
That wasn't the point i was making at all. Your understanding of how code works seems to be fundamentally flawed.

green = rs.testBundledOutput("back",colors.green)
and

green = false
is the exact same thing, provided green is not powered on when you call the the first function. Essentially meaning this

--green is off
green = rs.getInput("back",colors.green)
sleep(2)
--power green on during the sleep
print(green)
--prints false
green = rs.getInput("back",colors.green)
print(green)
--prints true
So, what i suggested was you do the following

while true do
  display()
  event, param1, param2, param3 = os.pullEvent()
  if event == "redstone" then
	green = rs.testBundledOutput("back",colors.green)
  elseif
  --other events
end
Edited on 24 April 2014 - 05:02 PM