Posted 20 October 2018 - 10:30 AM
Hi everyone!
I've been working on an Extreme Reactors reactor controller and now I've decided to add networking capabilities such as data readouts but I'm having trouble sending only when the stats update.
(here's my code)
if anyone has a better idea than declaring a variable and checking if it's still equal, it'd be very apreciated!
Sincereley:
Qwerty.
I've been working on an Extreme Reactors reactor controller and now I've decided to add networking capabilities such as data readouts but I'm having trouble sending only when the stats update.
(here's my code)
local function clear()
term.clear()
term.setCursorPos(1,1)
end
--defining variables and setting things
local reactor = peripheral.find("BigReactors-Reactor")
local x, y = term.getSize()
os.loadAPI("SliderAPI")
SliderAPI.createSlider("e", 2, 2, x-2, 3, colors.red, colors.gray)
local modem = peripheral.find("modem")
rednet.open("right") --assuming the modem is on top of the reactor controller
modem.open(65535)
while true do --main loop
clear()
--math stuff
local cap = reactor.getEnergyCapacity()
local strd = reactor.getEnergyStored()
local tlen = tostring(stdr,cap) --there are better ways of doing this but idk how
local len = string.len(tlen .." ") --without the added string the text wouldn't center properly, i don't know why
local percent = math.floor((strd/cap) * 100) -- floor it? yes, no, NO DONT FLOOR IT! FLOOR IT!!!
local tPercent = percent
--slide stuff
SliderAPI.updateSlider("e", percent)
SliderAPI.draw("e")
--rednet stuff
if tPercent ~= percent then
rednet.broadcast(percent,"percent")
rednet.broadcast(tostring(reactor.getActive()),"reacActive")
local cast = tostring(strd..","..cap)
rednet.broadcast(cast,"energy")
end
--write stuff
term.setCursorPos( x/2-len , y)
write(strd.."/"..cap)
term.setCursorPos( x/2-2, 1)
write("Energy")
sleep(0.1)
clear()
--controlling the reactor
reactor.setAllControlRodLevels(percent)
if percent >= 99 then reactor.setActive(false) else
reactor.setActive(true)
end
end
I also took the liberty to include the infamous sliders API i found on the forums, but that's not important.if anyone has a better idea than declaring a variable and checking if it's still equal, it'd be very apreciated!
Sincereley:
Qwerty.
Edited on 20 October 2018 - 09:03 AM