Here is the code:
dir = shell.dir().."/"
os.loadAPI(dir.."settings")
main = peripheral.wrap(settings.mainSide)
dis = 0
pkt = {"cellDis", os.getComputerID()}
main.open(101)
function mainLoop()
while true do
term.clear()
if dis>=1 and dis<=146 then
term.setBackgroundColor(colors.green)
--paintutils.drawLine(1,1,3,1,colors.green)
term.setCursorPos(1,1)
write(">>>")
term.setBackgroundColor(colors.black)
--print(dis)
elseif dis>=147 and dis<=181 then
term.setBackgroundColor(colors.orange)
--paintutils.drawLine(1,1,2,1,colors.orange)
term.setCursorPos(1,1)
write(">>")
term.setBackgroundColor(colors.black)
--print(dis)
elseif dis>=182 and dis<=220 then
term.setBackgroundColor(colors.red)
--paintutils.drawLine(1,1,1,1,colors.red)
term.setCursorPos(1,1)
write(">")
term.setBackgroundColor(colors.black)
--print(dis)
elseif dis == 0 then
term.setBackgroundColor(colors.red)
--paintutils.drawLine(1,1,3,1,colors.red)
term.setCursorPos(1,1)
write("N/A")
term.setBackgroundColor(colors.black)
--print(dis)
end
dis = 0
sleep(1)
main.transmit(101,101,pkt)
end
end
function listen()
while true do
event = {os.pullEvent()}
if event[1] == "modem_message" then
local side = event[2]
local freq = event[3]
local rfreq = event[4]
local msg = event[5]
dis = event[6]
--dist = tonumber(dis)
end
--elseif event[1] == "timer" and event[2] == timeout then
--print("unable to get location")
--break
end
end
main.transmit(101,101,pkt)
parallel.waitForAll(listen,mainLoop)
The problem is say is celltower A is 200 blocks away and cell tower B is 100 then it takes celltower A's measurement and it says you have 1 bar, instead of say 3. When you are out of celltower A's range then it connects to cell tower B and then you get 3 bars.