Posted 24 June 2014 - 06:19 AM
Hi guys,
I'm currently working on a program which allows me to see the status of my entire EU network.
Level Function displays the charge on a vertically stacked Monitor, while statusFunction should show additional information at a latter time.
level function gets it's information from other Computers which wirelessly broadcast a message. To be able to identify the different sending machines, I gave them unique reply channels when they broadcast their message.
The first version of this program had no functions or parallel commands and simply updated the status Monitor whenever the computer recieved a new message, as it waits for the os.pullEvent().
But I wanted it to update the status Monitor in 1 second intervalls, so I played around with the parallel.waitForAny() command, to see if I could get it working.
Unfortunately, it seems not to call the statusFunction, as it never reaches the print("status") line.
I'm betting it's only a detail which prevents the program from running as intended, but after a few hours long search I couldn't find the problem.
I want to add a giant Controll Monitor on the right side of the computer, showing the most vital Information about my EU Storage and Nuclear Reactors, so I would be glad if someone could point me to a good guide on the topic of displying Information on CC Monitors.
I'm pretty sure, that this variant to pass the information to my control room isn't the most elegant one, so if there's another possibility to retrieve the needed data from the other Computers, I would be glas to hear about it!
I'm currently working on a program which allows me to see the status of my entire EU network.
Level Function displays the charge on a vertically stacked Monitor, while statusFunction should show additional information at a latter time.
level function gets it's information from other Computers which wirelessly broadcast a message. To be able to identify the different sending machines, I gave them unique reply channels when they broadcast their message.
The first version of this program had no functions or parallel commands and simply updated the status Monitor whenever the computer recieved a new message, as it waits for the os.pullEvent().
But I wanted it to update the status Monitor in 1 second intervalls, so I played around with the parallel.waitForAny() command, to see if I could get it working.
Unfortunately, it seems not to call the statusFunction, as it never reaches the print("status") line.
I'm betting it's only a detail which prevents the program from running as intended, but after a few hours long search I couldn't find the problem.
modem = peripheral.wrap("left")
levelMonitor = peripheral.wrap("top")
levelMonitor.setTextScale(0.5)
statusMonitor = peripheral.wrap("right")
statusMonitor.setTextScale(1)
modem.open(2)
local stored = 0
local store = {}
for i=1, 5 do
store[i]=0
end
function levelFunction()
while true do
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if (replyChannel<6) then
store[replyChannel]=message
end
stored=0
for i=1, 5 do
stored=stored + store[i]
end
print("Currently stored: "..stored)
levelMonitor.setBackgroundColor(colors.red)
levelMonitor.clear()
levelMonitor.setBackgroundColor(colors.green)
levelMonitor.setTextColor(colors.red)
x,y = levelMonitor.getSize()
for yi=math.floor((1-stored/200000000)*y), y do
for xi=1,x do
levelMonitor.setCursorPos(xi,yi)
levelMonitor.write(" ")
end
end
end
end
function statusFunction()
while true do
print("status")
sx,sy=statusMonitor.getSize()
statusMonitor.clear()
statusMonitor.setCursor(sx-7,1)
statusMonitor.write("it worked")
sleep(10)
end
end
parallel.waitForAny(levelFunction(), statusFunction())
I want to add a giant Controll Monitor on the right side of the computer, showing the most vital Information about my EU Storage and Nuclear Reactors, so I would be glad if someone could point me to a good guide on the topic of displying Information on CC Monitors.
I'm pretty sure, that this variant to pass the information to my control room isn't the most elegant one, so if there's another possibility to retrieve the needed data from the other Computers, I would be glas to hear about it!