This code needs to run all the time to keep the main computer updated with it, i haven't found another way to do it. I have 2 turtles that run basically this code, i can run 1 for awhile but it eventually bugs out as well if i don't restart the turtle everyonce in awhile. I thought about making functions for each thing but wouldn't that be the same as running the code like this
This is the code i have the problem with
Spoiler
os.loadAPI("ocs/apis/sensor")
local debug = 1
rednet.open("right")
while true do
local sR = sensor.wrap("left")
local mFsU = sR.getTargetDetails("0,-1,0")
local msg = textutils.serialize(mFsU)
rednet.broadcast(msg)
if debug == 1 then
print(textutils.unserialize(mFsU.Stored))
print(textutils.unserialize(mFsU.Capacity))
print(textutils.unserialize(mFsU.StoredPercentage))
print(textutils.unserialize(mFsU.Output))
end
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
rednet.close("right")
This code is the reciver computer which recives info from both turtles, i tried to make it so i didn't need to add so many
local id,message = rednet.receive()
local scan = textutils.unserialize(message)
and
local id1,message1 = rednet.receive()
local scan1 = textutils.unserialize(message1)
But when i didn't have them in the loop it wouldn't update and if i just put them in the loop the graph won't draw
I have no problem with this code it works fine
Spoiler
os.loadAPI("ocs/apis/graph")
montop = peripheral.wrap("top")
monleft = peripheral.wrap("left")
monright = peripheral.wrap("right")
rednet.open("back")
gradient1 = {colors.blue, colors.cyan, colors.green, colors.lime}
gradient2 = {colors.purple, colors.magenta, colors.red, colors.orange}
--Menus
local id,message = rednet.receive()
local scan = textutils.unserialize(message)
local id1,message1 = rednet.receive()
local scan1 = textutils.unserialize(message1)
local cableSide = "bottom"
--montop.write(scan1.Heat)
function setBundledColor(side, color, state)
if state then
if not colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
end
else
if colors.test(rs.getBundledOutput(side), color) then
rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
end
end
end
function checkReactorHeat()
if scan.Heat == 0 then
setBundledColor(cableSide, colors.lime, true)
else
setBundledColor(cableSide, colors.lime, false)
end
heatLevel = scan.Heat
return heatLevel
end
function checkBreederHeat()
if scan1.Heat == 0 then
setBundledColor(cableSide, colors.white, false)
else
setBundledColor(cableSide, colors.white, true)
end
heatLevel1 = scan1.Heat
return heatLevel1
end
function checkReactorEng()
if scan.Output > 0 then
eNg = scan.Output
else
eNg = scan.Output +1
end
return eNg
end
function checkBreederEng()
if scan1.EnergyEmitted > 0 then
eNg1 = scan1.EnergyEmitted
else
eNg1 = scan1.EnergyEmitted +1
end
return eNg1
end
--local grtop, err = graph.new(montop, {checkReactorHeat ,checkBreederHeat, checkReactorEng, checkBreederEng}, {"Reactor 1 Heat", "Breeder 1 Heat", "Reactor 1 Energy Output", "Breeder 1 Energy Output"}, {gradient1, gradient2, gradient3, gradient4}, {0, 0, 0, 0}, {scan.MaxHeat, scan1.MaxHeat, scan.EnergyEmitted, scan1.EnergyEmitted}, true)
local grleft, err = graph.new(monleft, {checkReactorHeat ,checkBreederHeat}, {"Reactor 1 Heat", "Breeder 1 Heat"}, {gradient1, gradient2}, {0, 0}, {scan.MaxHeat, scan1.MaxHeat}, true)
local grright, err = graph.new(monright, {checkReactorEng, checkBreederEng}, {"Reactor 1 Energy Output", "Breeder 1 Energy Output"}, {gradient1, gradient2}, {0, 0}, {scan.EnergyEmitted, scan1.EnergyEmitted}, true)
while true do
id,message = rednet.receive()
scan = textutils.unserialize(message)
id1,message1 = rednet.receive()
scan1 = textutils.unserialize(message1)
--grtop:draw()
grleft:draw()
grright:draw()
-- montop.setCursorPos(1,1)
-- montop.write(scan1.Heat)
--montop.clear()
sleep(1)
end
rednet.close("back")
As you can tell it's prolly not the best way to code this but it's all i know at the moment. Is it just me or does the code tag remove me indentation