Posted 19 November 2012 - 02:51 PM
Hello, I am having trouble with a segment of code I have constructed involving the split command, my program is in two parts a listener which output information on a screen from rednet messages here is the listener code:
And here is the client code that sends the rednet message : the error i get is that the variable "result" is nill but split should set it?
Spoiler
rednet.open("back")
door = "Unknown"
result = { }
p2 = ""
lights = "Unknown"
mon = peripheral.wrap("top")
mon.clear()
mon.setTextScale(2)
repeat
local event,p1,p2,p3 = os.pullEvent()
if event=="rednet_message" then
result = split(p2, ":")
print (split(p2, ":"))
result1 = result
result2 = result
if result1 == "door" then door = result2
elseif result1 == "lights" then lights = result2
end
mon.setCursorPos(2,2)
mon.write("Door status: "..door)
mon.setCursorPos(2,3)
mon.write("Lights status: "..lights)
end
until event=="char" and p1=="x"
And here is the client code that sends the rednet message : the error i get is that the variable "result" is nill but split should set it?
Spoiler
rednet.open("back")
redstone.setOutput("back", false)
sleep(5)
rednet.send(4, "door : open")
redstone.setOutput("back", true)
rednet.close("back")