Posted 24 August 2014 - 07:32 PM
I got a little problem with my program.
The program should display the actual data about a reactor connected to it, here is a picture how it looks at this moment:
My problem is that i want to update the data displayed BUT be able to click on the monitor to activate or deactivate the reactor.
I already tried to use parallel but then i couldnt click on anything, it just updated the data.
Here's the code without the parallel stuff:
And here the code with the parallel thing i tried:
There was no different between waitForAll or waitForAny.
The program should display the actual data about a reactor connected to it, here is a picture how it looks at this moment:
Spoiler
My problem is that i want to update the data displayed BUT be able to click on the monitor to activate or deactivate the reactor.
I already tried to use parallel but then i couldnt click on anything, it just updated the data.
Here's the code without the parallel stuff:
Spoiler
slc = 0
reactor = peripheral.wrap("BigReactors-Reactor_0")
function drawBackground()
background = paintutils.loadImage("bg_cut")
paintutils.drawImage(background,1,1)
end
function drawTitleBar()
term.setCursorPos(1,1)
term.setBackgroundColor(256)
term.setTextColor(1)
term.setCursorPos(35,1)
term.write(" Menu ")
term.setCursorPos(2,1)
term.write("Update")
term.setBackgroundColor(8)
end
function drawReactorStats()
term.setCursorPos(2,3)
term.setTextColor(colors.black)
term.write("Reaktor:")
if reactor.getActive() == true then
term.setCursorPos(11,3)
term.setTextColor(colors.green)
term.write("Aktiv")
elseif reactor.getActive() == false then
term.setCursorPos(11,3)
term.setTextColor(colors.red)
term.write("Inaktiv")
end
term.setCursorPos(2,4)
term.setTextColor(colors.black)
local r_storedenergy = reactor.getEnergyStored()
term.write("Energie: ")
if r_storedenergy >= 7500000 then
term.setCursorPos(11,4)
term.setTextColor(colors.green)
term.write(r_storedenergy.."RF")
elseif r_storedenergy < 2000000 then
term.setCursorPos(11,4)
term.setTextColor(colors.red)
term.write(r_storedenergy.."RF")
elseif r_storedenergy >= 2000000 and r_storedenergy < 7500000 then
term.setCursorPos(11,4)
term.setTextColor(colors.black)
term.write(r_storedenergy.."RF")
end
term.setCursorPos(2,5)
term.setTextColor(colors.black)
local r_fueltemp = reactor.getFuelTemperature()
term.write("Kern-Temperatur: ")
if r_fueltemp < 500 then
term.setCursorPos(19,5)
term.setTextColor(colors.blue)
term.write(r_fueltemp.."C")
elseif r_fueltemp >= 500 and r_fueltemp < 1000 then
term.setCursorPos(19,5)
term.setTextColor(colors.orange)
term.write(r_fueltemp.."C")
elseif r_fueltemp >= 1000 then
term.setCursorPos(19,5)
term.setTextColor(colors.red)
term.write(r_fueltemp.."C")
end
end
function drawDesktop()
term.setBackgroundColor(1)
term.clear()
drawBackground()
drawTitleBar()
drawReactorStats()
end
function drawDropDownMenu1()
term.setTextColor(1)
term.setBackgroundColor(256)
term.setCursorPos(35,2)
term.write(" Beenden ")
term.setCursorPos(35,3)
term.write(" Neustarten ")
term.setCursorPos(35,4)
term.write(" Update ")
end
drawDesktop()
while true do
local event, button, X, Y = os.pullEventRaw()
if slc == 0 then
if event == "mouse_click" then
if X >= 35 and X <= 41 and Y == 1 and button==1 then --open menu
drawDropDownMenu1()
slc = 1
elseif X >= 2 and X <= 8 and Y == 1 and button==1 then
drawDesktop()
elseif X >= 11 and X <= 18 and Y == 3 and button==1 then
if reactor.getActive() == false then
reactor.setActive(true)
drawDesktop()
elseif reactor.getActive() == true then
reactor.setActive(false)
drawDesktop()
end
drawDesktop()
else
drawDesktop()
end
end
elseif slc == 1 then
if event == "mouse_click" then
if X >= 35 and X <= 48 and Y == 2 and button==1 then slc=0 --beenden
error("Programm wurde beendet")
elseif X >= 35 and X <= 46 and Y == 3 and button==1 then slc=0 --pc neustart
os.reboot()
elseif X >= 35 and X <= 44 and Y == 4 and button==1 then slc=0 --update values
drawDesktop()
else
slc = 0
drawDesktop()
end
end
end
end
And here the code with the parallel thing i tried:
Spoiler
slc = 0
reactor = peripheral.wrap("BigReactors-Reactor_0")
function drawBackground()
background = paintutils.loadImage("bg_cut")
paintutils.drawImage(background,1,1)
end
function drawTitleBar()
term.setCursorPos(1,1)
term.setBackgroundColor(256)
term.setTextColor(1)
term.setCursorPos(35,1)
term.write(" Menu ")
term.setCursorPos(2,1)
term.write("Update")
term.setBackgroundColor(8)
end
function drawReactorStats()
while true do
term.setCursorPos(2,3)
term.setTextColor(colors.black)
term.write("Reaktor:")
if reactor.getActive() == true then
term.setCursorPos(11,3)
term.setTextColor(colors.green)
term.write("Aktiv")
elseif reactor.getActive() == false then
term.setCursorPos(11,3)
term.setTextColor(colors.red)
term.write("Inaktiv")
end
term.setCursorPos(2,4)
term.setTextColor(colors.black)
local r_storedenergy = reactor.getEnergyStored()
term.write("Energie: ")
if r_storedenergy >= 7500000 then
term.setCursorPos(11,4)
term.setTextColor(colors.green)
term.write(r_storedenergy.."RF")
elseif r_storedenergy < 2000000 then
term.setCursorPos(11,4)
term.setTextColor(colors.red)
term.write(r_storedenergy.."RF")
elseif r_storedenergy >= 2000000 and r_storedenergy < 7500000 then
term.setCursorPos(11,4)
term.setTextColor(colors.black)
term.write(r_storedenergy.."RF")
end
term.setCursorPos(2,5)
term.setTextColor(colors.black)
local r_fueltemp = reactor.getFuelTemperature()
term.write("Kern-Temperatur: ")
if r_fueltemp < 500 then
term.setCursorPos(19,5)
term.setTextColor(colors.blue)
term.write(r_fueltemp.."C")
elseif r_fueltemp >= 500 and r_fueltemp < 1000 then
term.setCursorPos(19,5)
term.setTextColor(colors.orange)
term.write(r_fueltemp.."C")
elseif r_fueltemp >= 1000 then
term.setCursorPos(19,5)
term.setTextColor(colors.red)
term.write(r_fueltemp.."C")
end
sleep(3)
end
end
function drawDesktop()
term.setBackgroundColor(1)
term.clear()
drawBackground()
drawTitleBar()
drawReactorStats()
end
function drawDropDownMenu1()
term.setTextColor(1)
term.setBackgroundColor(256)
term.setCursorPos(35,2)
term.write(" Beenden ")
term.setCursorPos(35,3)
term.write(" Neustarten ")
term.setCursorPos(35,4)
term.write(" Update ")
end
drawDesktop()
function actualProgram()
while true do
local event, button, X, Y = os.pullEventRaw()
if slc == 0 then
if event == "mouse_click" then
if X >= 35 and X <= 41 and Y == 1 and button==1 then --open menu
drawDropDownMenu1()
slc = 1
elseif X >= 2 and X <= 8 and Y == 1 and button==1 then
drawDesktop()
elseif X >= 11 and X <= 18 and Y == 3 and button==1 then
if reactor.getActive() == false then
reactor.setActive(true)
drawDesktop()
elseif reactor.getActive() == true then
reactor.setActive(false)
drawDesktop()
end
drawDesktop()
else
drawDesktop()
end
end
elseif slc == 1 then
if event == "mouse_click" then
if X >= 35 and X <= 48 and Y == 2 and button==1 then slc=0 --beenden
error("Programm wurde beendet")
elseif X >= 35 and X <= 46 and Y == 3 and button==1 then slc=0 --pc neustart
os.reboot()
elseif X >= 35 and X <= 44 and Y == 4 and button==1 then slc=0 --update values
drawDesktop()
else
slc = 0
drawDesktop()
end
end
end
end
end
while true do
parallel.waitForAll(actualProgram(),drawReactorStats())
end
There was no different between waitForAll or waitForAny.