Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Azrdraco

OC and Big Reactors

Question

Hello, 

 

I'm working on a program to run my Big Reactor (ala Direwolf20's recent CC program)

 

I started yesterday knowing very little about writing code and have managed to program the basic function which I wanted to start out with. I'm hoping to add more monitoring and adjustment functions later as I learn more, but this what I need to start off.

 

I want my reactor to shut off when the energy buffer is at 90% and restart when the buffer is down to 10%. My buffer is currently 10mil RF.

 

It works, once. If I run when the buffer is near full, it will shut down, and if I run the program when the buffer is low, it will start the reactor. It does not, however, shut the reactor back down once it is near full unless I rerun the program.

 

My question is what do I need to add in order to have this run in the background and continuously manage my reactor?

 

Here's my code: 

 

component = require("component")

 

RF_BUFFER_MAX = 9000000

RF_BUFFER_MIN = 1000000

 

for _, reactor in pairs(REACTORS) do

 

  if reactor.getEnergyStored() >= RF_BUFFER_MAX then

    reactor.setActive(false)

    print("Reactor is offline")

  else if reactor.getEnergyStored() <=RF_BUFFER_MIN then

    reactor.setActive(true)

    print("Reactor is online")

  end

end

 

Thank you for any insight that you can give!

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
  • Solution

To simply make this loop run forever you can simply wrap up the current code in a while loop.

local component = require("component") --// just a tip. especially if running in the background,
-- if you're not sharing this variable with other programs... localize it..
 
local RF_BUFFER_MAX = 9000000
local RF_BUFFER_MIN = 1000000
local running = true -- set to false to kill the program
 
while running do
  -- your code
  for _, reactor in pairs(REACTORS) do
    if reactor.getEnergyStored() >= RF_BUFFER_MAX then
      reactor.setActive(false)
      print("Reactor is offline")
    else if reactor.getEnergyStored() <=RF_BUFFER_MIN then
      reactor.setActive(true)
      print("Reactor is online")
    end
  end -- end for / end your code
end -- end while

To run this in the background use the process api.

local process = require "process"
process.load("absolutePathToYourProgram",<>,<>,<>)-- '<>' arguments aren't necessary 

With some tinkering your program could start the process when started with a certain argument and when the process is loaded you could ask the state of your running process with another call to the program with another flag. ie: yourProgram -s //starts the process in the background; yourProgram -i //prints the state info you want from your process; pass -k or something to kill the program

Link to post
Share on other sites
  • 0

edit: i need to think about it

management script:

local arg = ...
local process = require "process"
local component = require "component"
local RF_BUFFER_MIN, RF_BUFFER_MAX, running = 1000000, 9000000, false
local REACTORS = {} -- // your list of reactors in the for loop of program
local thisProcess

if arg == "-s" then
  if running then error("program already running!") end
  -- // process.load will feed this programs environment or local scope to your program, thus,
  -- // defining component and rf buffer limits in here so we can change them if we get more complex later.
  thisProcess = process.load("pathToProgram")
elseif arg == "-i" then
 -- // yadda yadda
end

--

reactor bg program:


while running do
  -- // your code
  for _, reactor in pairs(REACTORS) do 
    if reactor.getEnergyStored() >= RF_BUFFER_MAX then
      reactor.setActive(false)
      print("Reactor is offline")
    else if reactor.getEnergyStored() <=RF_BUFFER_MIN then
      reactor.setActive(true)
      print("Reactor is online")
    end
  end -- // end for / end your code
end -- // end while

i think this should work with a little testing and tweaking..

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.