This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
luludu33610's profile picture

Big Reactor statistics display

Started by luludu33610, 30 November 2014 - 08:28 AM
luludu33610 #1
Posted 30 November 2014 - 09:28 AM
I try to do a program which display the Reactor and turbines statistics on a screen.
I have 2 computer who emit on rednet the informations from the first turbine and the reactor.
This program won't work since i add the Reactor part.
This is the display program.



local screen = peripheral.wrap("left")

rednet.open("top")

data = {}
data[20] = {}
data[2] = {}

os.sleep(2)

--Windows
local t1 = window.create(screen,1,1,29,19)
local t2 = window.create(screen,53,1,29,19)
local r1 = window.create(screen,30,1,24,40)


function fetchData()
  while true do
	e,a,b,c = os.pullEvent("rednet_message")
	if (a == 2 or a == 20) then
	  data[a] = textutils.unserialize(B)/>
	end
  end
end


function Tu1() --Turbine1 display
	term.redirect(t1)
	if data[20]["Etat"] == 1 then  turbine_statut = paintutils.loadImage("image/turbine_on_1") else turbine_statut = paintutils.loadImage("image/turbine_off") end
	t1.setBackgroundColor(colors.black)
	t1.clear()
	t1.setCursorPos(10, 1)
	t1.write("Turbine 1")
	t1.setCursorPos(3, 17)
	t1.print("Rotor Speed : "..data[20]["Rotor"].." RPM")
	t1.setCursorPos(3, 19)
	t1.print("Energy Buffer : "..textutils.serialize(data[20]["Energy"]).." RF/t")
	paintutils.drawImage(turbine_statut, 9, 4)
end

function Re1() --Reactor display
	term.redirect(r1)
	if data[2]["Active"] == 1 then  reactor_statut = paintutils.loadImage("image/reactor_on_1") else reactor_statut = paintutils.loadImage("image/reactor_off") end
	r1.setBackgroundColor(colors.black)
	r1.clear()
	r1.setCursorPos(10, 1)
	r1.write("Reactor")
	paintutils.drawImage(reactor_statut, 8, 5)
end

function afficheData()
  os.sleep(5)
  while true do
   Re1()
   Tu1()
  end
end

parallel.waitForAll(fetchData, afficheData)


The computer for reactor get the id 2 and the computer for the turbine get the id 20
If you need the programs in the 2 other computer ask me pls.
And really sorry for my english.
Edited on 02 December 2014 - 06:38 AM
Bomb Bloke #2
Posted 02 December 2014 - 01:42 AM
This program won't work since i add the Reactor part.

What DOES it do? How is what it does, different to what you want it to do?

The only obvious problem I can see is that data["Etat"] will never be 1. Did you mean data[20]["Etat"]?
luludu33610 #3
Posted 02 December 2014 - 07:36 AM
Sorry i make a mistake when I rewrite the program after test but it's always do a attemp to call nil but i think all function are ok. An d it was well a fail. thanks.
luludu33610 #4
Posted 02 December 2014 - 04:18 PM
Problem resolve the windows called t1 don't need to be add every where