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

Cannot figure out nil bug

Started by q23345, 03 February 2016 - 12:54 AM
q23345 #1
Posted 03 February 2016 - 01:54 AM
I simply can't see why my code isn't working. It's supposed to interface with a reactor from big reactors and update a monitor in our base with stats, i keep getting an error for line 27 {s.write("Stored Energy")} but i don't know why. (both computers interface over wire rednet, the "master" computer is ID: 3 and the "slave" is ID: 4)
Here is the master code

s = peripheral.wrap("back")
s.clear()
s.setCursorPos(0,0)
s.write("Testing Screen")
print("set peripheral")
rednet.open("top")
print("opened top")
function Wait()
s = peripheral.wrap("back")
print("waiting for active")
s.write("babies")
local ID, stat = rednet.receive()
if stat==true then
  s.setCursorPos(0,0)
  s.write("On")
end
if stat==false then
  s.setCursorPos(0,0)
  s.write("Off")
end
print("printed active to screen")
rednet.send(4,"1")
print("waiting for e stored")
local ID, stat = rednet.receive()
print("rednet received")
stat = tosting(stat)
s.write("Stored Energy")
print("printed e stored")

rednet.send(4,"1")
print("waiting for fuel temp")
ID, stat = rednet.receive()
s.print("Fuel Temperature: "..tosting(stat))
print("printed fuel temp")
rednet.send(4,"4")
print("waiting for case temp")
ID, stat = rednet.receive()
s.print("Casing Tempurature: "..tosting(stat))
print("printed case temp")
rednet.send(4,"4")
print("waiting for fuel amount")
ID, stat = rednet.receive()
s.print("Amount Of Fuel: "..tosting(stat))
print("printing fuel amount")
rednet.send(4,"4")
print("waiting for energy produced")
ID, stat = rednet.receive()
s.print("Energy Produced: "..tosting(stat))
print("printed energy produced")
rednet.send(4,"1")
print("waiting for fuel used")
ID, stat = rednet.receive()
s.print("Fuel Consumed: "..tosting(stat))
print("printed fuel used")
rednet.send(4,"1")
end
function reset()
s.clear()
s.setCursorPos(0,0)
end
while true do
Wait()
reset()
end
and here is the slave code

rednet.open("back")
r = peripheral.wrap("right")
function Ask()
print("getting active")
local stat = r.getActive
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting energy")
local stat = r.getEnergyStored
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting fuel temp")
local stat = r.getFuelTemperature
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting case temp")
local stat = r.getCasingTempurature
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting fuel amount")
local stat = r.getFuelAmount
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting energy produced")
local stat = r.getEnergyProducedLastTick
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
print("getting fuel consumed")
local stat = r.getFuelConsumedLastTick
rednet.send(3,stat)
print("sent")
print("waiting")
rednet.receive()
end

while true do
Ask()
end
Bomb Bloke #2
Posted 03 February 2016 - 02:13 AM
stat = tosting(stat)

"tosting" is nil.