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

(rednet) Reactor program not working

Started by jarifle, 17 May 2015 - 07:44 AM
jarifle #1
Posted 17 May 2015 - 09:44 AM
Hello,

I want my reactor to send me a status update with the wireless computer.

I'm having quite alot of trouble with this first things first: the program does not clear the menu from the screen (it uses buttons) but other programs that are run do.
The program does kinda work but it is not receiving the variable but it is sending it.
Here is the code of the reactor computer and it also displays stuff on a monitor

mon = peripheral.wrap("monitor_0")
r = peripheral.wrap("BigReactors-Reactor_0")
cell = peripheral.wrap("tile_thermalexpansion_cell_resonant_name_0")

function active()
  if r.getActive() == true then
    a = "On"
    ca = colors.lime
  else
    a = "Off"
    ca = colors.red
  end
end
function lastTick()
  if r.getEnergyProducedLastTick() == 0 then
    b = "0"
    ct = colors.red
  else
    b = math.floor(r.getEnergyProducedLastTick())
    ct = colors.lime
  end
end
function cellEnergy()
  energy = math.floor(math.floor(cell.getEnergyStored())/math.floor(cell.getMaxEnergyStored())*100)
  if energy >= 60 then
    ce = colors.lime
  elseif energy <= 20 then
    ce = colors.red
  else
    ce = colors.orange
  end
end
function main()
  mon.clear()
  mon.setCursorPos(3,1)
  mon.setTextScale(4)
  mon.setTextColor(colors.yellow)
  mon.write(" Reactor")
  active()
  mon.setCursorPos(1,2)
  mon.setTextColor(ca)
  mon.write(a)
  lastTick()
  mon.setCursorPos(1,3)
  mon.setTextColor(ct)
  mon.write(B)/>
  if r.getEnergyStored() <= 0 then
    r.setActive(true)
  end
  if r.getEnergyStored() >= 5000000 then
    r.setActive(false)
  end
 
  mon.setCursorPos(5,4)
  mon.setTextColor(colors.cyan)
  mon.write(" Cell")
 
  cellEnergy()
  mon.setCursorPos(1,5)
  mon.setTextColor(ce)
  mon.write(energy)
  mon.write(" %")
  sleep(0.5)
end
function test()
  rednet.open("right")
  id, message = rednet.receive(2)
  if message == "reactor" then
    print("test")
    rednet.send(6,{msgID = "RednetMiner",val = a}) --# sending message to computer 6
  end
  sleep(0.5)
end
while true do
  parallel.waitForAll(test, main)
end

This is the program on the pocket computer.

rednet.open("back")
term.clear()
term.setCursorPos(1,1)
print("Reactor status")
rednet.send(8, "reactor")
--What do i do here to receive the variabel "a" from the other program?

This is the menu on the pocket computer.

os.loadAPI("buttons")
rednet.open("back")
local guiButtons = {}
local running = true
close = function()
  buttons.setColor(guiButtons.buttonClose, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonClose, colors.white, colors.red)
  buttons.draw()
  term.clear()
  term.setCursorPos(1,1)
  error()
end
door = function()
  rednet.send(7,"door")
  buttons.setColor(guiButtons.buttonDoor, colors.white, colors.lime)
  buttons.draw()
  sleep(3)
  buttons.setColor(guiButtons.buttonDoor, colors.white, colors.red)
  buttons.draw()
end

miner = function()
  buttons.setColor(guiButtons.buttonMiner, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonMiner, colors.white, colors.red)
  buttons.draw()
  shell.run("miner")
end
Eminer = function()
  buttons.setColor(guiButtons.buttonEminer, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonEminer, colors.white, colors.gray)
  buttons.draw()
  shell.run("edit miner")
end
edit = function()
  buttons.setColor(guiButtons.buttonEdit, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonEdit, colors.white, colors.red)
  buttons.draw()
  shell.run("edit menu")
  sleep(0.5)
  os.reboot()
end
reactor = function()
  buttons.setColor(guiButtons.buttonReactor, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonReactor, colors.white, colors.red)
  buttons.draw()
  shell.run("reactor")
end
Ereactor = function()
  buttons.setColor(guiButtons.buttonEreactor, colors.white, colors.lime)
  buttons.draw()
  sleep(0.5)
  buttons.setColor(guiButtons.buttonEreactor, colors.white, colors.gray)
  buttons.draw()
  shell.run("edit reactor")
end
guiButtons.buttonClose = buttons.register(26, 1, 1, 1, colors.white, colors.red, "X", close)
guiButtons.buttonDoor = buttons.register(3, 5, 8, 1, colors.white, colors.red, "Door", door)
guiButtons.buttonEminer = buttons.register(1, 7, 1, 1, colors.white, colors.gray, "E", Eminer)
guiButtons.buttonMiner = buttons.register(3, 7, 8, 1, colors.white, colors.red, "Miner", miner)
guiButtons.buttonEdit = buttons.register(1, 1, 4, 1, colors.white, colors.red, "Edit", edit)
guiButtons.buttonReactor = buttons.register(17, 5, 8, 1, colors.white, colors.red, " Reactor", reactor)
guiButtons.buttonEreactor = buttons.register(15, 5, 1, 1, colors.white, colors.gray, "E", Ereactor)
buttons.draw()
while true do
  local eventArray = {os.pullEvent()}
  buttons.event(eventArray)
  buttons.draw()
end

Sorry for the long post and code.
Bomb Bloke #2
Posted 18 May 2015 - 12:57 AM
rednet.open("back")
term.clear()
term.setCursorPos(1,1)
print("Reactor status")
rednet.send(8, "reactor")
--What do i do here to receive the variabel "a" from the other program?

Well, the other script is doing this:

rednet.send(6,{msgID = "RednetMiner",val = a}) --# sending message to computer 6

So to catch that, you might do:

local id, message = rednet.receive()
print(message.val)  --> Prints whatever the value of "a" was
jarifle #3
Posted 18 May 2015 - 06:42 PM
Oke i didn't crash or anything but it also didn't do anything.
Basicly the button press does not clear the screen or anything

Edit: nvm it booted but still didn't receive it
i think its not possible.
Edited on 18 May 2015 - 06:35 PM