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

Updating information

Started by tysciman7, 07 February 2014 - 01:51 PM
tysciman7 #1
Posted 07 February 2014 - 02:51 PM
Hello, I am a decent programmer in lua. But I still have trouble. I am currently setting up a nuclear reactor console monitor. With the help of open peripherals. My problem is that I do not know how to update the heat and eu/t for it to constantly display the information in real time. My code for the receiver is where I am going to display the information. He is the reactor console(the sender connected to the reactor) http://pastebin.com/aaUDricv
And here is the receiver in the control room. http://pastebin.com/4sPcFVtD
LBPHacker #2
Posted 07 February 2014 - 05:14 PM
Got a bunch of suggestions for you:

1) Use locals: You're cluttering the global environment with those variables. With that many variables, I'd say just grab and localize all of them at once. Insert this line at the beginning of reactor:
local p, maxHeat, eu, safeHeat, heat
And this at the beginning of test:
local p1, p2, w1, h1, w2, h2, rec1Heat, rec1Eu
More about locals.

2) rednet doesn't send multiple variables, it sends only one variable at a time:
rednet.send(108, heat .. "@" .. eu)
And of course it receives only one variable as well:
local id, rec1Info = rednet.receive()
rec1Heat, rec1Eu = rec1Info:match("^([%d%.]*)@([%d%.]*)$") -- be aware, rec1Heat and rec1Eu are strings now

3) Displaying heat in reactor:
term.setCursorPos(1, 1)
term.clearLine()
term.write(tostring(heat))

4) Displaying heat and EU income in test:
p1.clear()
p1.setCursorPos(1, 3)
p1.write("Current Heat: " .. rec1Heat)
p1.setCursorPos(1, 5)
p1.write("EU Income (/T): " .. rec1Eu)

5) Checking if it really was reactor that sent the message to test:
function check1()
    repeat
        id, rec1Info = rednet.receive()
    until id == 107 -- the ID of the computer on which reactor is running
end

6) Why do you wrap monitor_3 if you never use it?
Edited on 07 February 2014 - 04:16 PM
tysciman7 #3
Posted 08 February 2014 - 12:18 AM
Thank you very much, monitor 3 is for a monitor that is almost going to emulate monitor 2. Monitor three will be a breeder reactor.