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

Big Reactors Turbine Monitoring Help

Question

Ok, so, I'm playing on a modpack (Tekkify) that has both Big Reactors and OpenComputers, and I'm trying to write a program that monitors a turbine I have set up after I start the program. I sadly don't know a lot about lua or OC on my own to fix this, so I'm looking to get some help possibly from people who have more know-how on with OC. I've already written up a rough mock of what I want, though it doesn't quite work as I had imagined-- it goes through the program once, prints the items I'm attempting to track to the screen once, I was using a while loop to hopefully make it check the values over and over, but it doesn't seem to be doing that.

local term = require("term")
local component = require("component")

local turbine = component.br_turbine
local tActive = turbine.getActive()
local tRPM = math.ceil(tonumber(turbine.getRotorSpeed()))
local tRf = math.ceil(tonumber(turbine.getEnergyStored()))
local tRfPt = math.ceil(tonumber(turbine.getEnergyProducedLastTick()))

while tActive do
  os.sleep(1)
  term.clear()
  print(tRPM, " RPM")
  print(tRf, " RF Stored")
  print(tRfPt, " RF/t")
end

If, due to my lack of knowledge of how loops work other than them just looping, I actually did what I was hoping for wrong, please, tell me how I can fix it so I might learn for future instances. Thank you in advance!

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  • Solution

Ok, so, I'm playing on a modpack (Tekkify) that has both Big Reactors and OpenComputers, and I'm trying to write a program that monitors a turbine I have set up after I start the program. I sadly don't know a lot about lua or OC on my own to fix this, so I'm looking to get some help possibly from people who have more know-how on with OC. I've already written up a rough mock of what I want, though it doesn't quite work as I had imagined-- it goes through the program once, prints the items I'm attempting to track to the screen once, I was using a while loop to hopefully make it check the values over and over, but it doesn't seem to be doing that.


local tActive = turbine.getActive()

while tActive do

If, due to my lack of knowledge of how loops work other than them just looping, I actually did what I was hoping for wrong, please, tell me how I can fix it so I might learn for future instances. Thank you in advance!

 

The reason why it only prints once is that you end the while loop when the turbine is disabled. This of course, ends the program. If you want to keep the program running at all times yet only print info if the turbine is on, then your code should look more like this:

local term = require("term")
local component = require("component")

local turbine = component.br_turbine
local tRPM = math.ceil(tonumber(turbine.getRotorSpeed()))
local tRf = math.ceil(tonumber(turbine.getEnergyStored()))
local tRfPt = math.ceil(tonumber(turbine.getEnergyProducedLastTick()))

while true do --keep program running at all times
  os.sleep(0.1)
  if turbine.getActive() then --check to make sure that the turbine is on
   os.sleep(1)
   term.clear()
   print(tRPM, " RPM")
   print(tRf, " RF Stored")
   print(tRfPt, " RF/t")
  end
end

Happy to help. Let me know if you have any more problems.

Link to post
Share on other sites
  • 0

Thank you for pointing that out! I ah, didn't quite think to do that. Bah. But aside from that, I've come into a new problem. When I start the program now, just as you have it above, it updates it just once, showing it as it is the first time it checks it, and then loops again, but doesn't update the values of the RPM and others. I even checked by increasing and decreasing the RPM to confirm it. That is a bit of a crucial part of the monitoring, so I would like to know what is wrong if anything is. Again, thank you in advanced!

Link to post
Share on other sites
  • 0

Thank you for pointing that out! I ah, didn't quite think to do that. Bah. But aside from that, I've come into a new problem. When I start the program now, just as you have it above, it updates it just once, showing it as it is the first time it checks it, and then loops again, but doesn't update the values of the RPM and others. I even checked by increasing and decreasing the RPM to confirm it. That is a bit of a crucial part of the monitoring, so I would like to know what is wrong if anything is. Again, thank you in advanced!

To keep values updating, you need to move this part into a loop. There's a code:

local term = require("term")
local component = require("component")

local turbine = component.br_turbine
local tRPM, tRf, tRfPt                -- Not to spam with 'local' in a loop


while true do
  if turbine.getActive() then              -- If turbine IS active, then get and print out info...
    tRPM = math.ceil(tonumber(turbine.getRotorSpeed()))               --   Get
    tRf = math.ceil(tonumber(turbine.getEnergyStored()))              -- turbine
    tRfPt = math.ceil(tonumber(turbine.getEnergyProducedLastTick()))  --  info

    term.clear()
    print(tRPM .. " RPM")
    print(tRf .. " RF Stored")
    print(tRfPt .. " RF/t")
    os.sleep(1)
  else              -- If not, then
    os.sleep(0.25)  -- sleep for 0.25 seconds
  end
end
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.