Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This function is required because the handle
- -- to the fusion reactor can return nil after creation
- function attempt(fun_name, if_true_do, if_false_do)
- reactor = peripheral.find("fissionReactorLogicAdapter")
- if reactor == nil or reactor[fun_name] == nil then
- status, result = pcall(if_false_do)
- return result
- end
- status, result = pcall(reactor[fun_name])
- return if_true_do(result)
- end
- while not peripheral.find("fissionReactorLogicAdapter") do
- sleep(1)
- print("Waiting for reactor to come online...")
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Script is active.")
- -- Steam percentage
- target_level = 0.9
- -- Coolant percentage
- min_coolant = 0.9
- while true do
- -- We assume the worst possible state
- steam_level = attempt("getHeatedCoolantFilledPercentage", function(level) return level end, function() return 0 end)
- coolant_level = attempt("getCoolantFilledPercentage", function(level) return level end, function() return 0 end)
- damage_level = attempt("getDamagePercent", function(damage) return damage end, function() return 100 end)
- waste_level = attempt("getWasteFilledPercentage",function(level) return level end, function() return 100 end)
- redstone_allowed = rs.getInput("front")
- should_run = steam_level < target_level and waste_level <= 0 and redstone_allowed and coolant_level > min_coolant and damage_level <= 0
- current_state = attempt("getStatus", function(status) return status end, function() return true end)
- term.setCursorPos(1,2)
- term.clearLine()
- if current_state ~= should_run then
- if should_run then
- attempt("activate", function(v) return nil end, function() return nil end)
- term.write("Switched reactor status: on")
- else
- attempt("scram", function(v) return nil end, function() return nil end)
- term.write("Switched reactor status: off")
- end
- else
- term.write("Reactor is currently " .. (current_state and "running" or "stopped"))
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement