Posted 20 January 2013 - 01:07 PM
I have run into a strange problem whit this code:
Sender code:
The problem lies at line 20
The lone number "1" you see below "Enter Password" is the Id of the computer it is run on. It seems to vary depending on the Id of the computer i run the code on.
I just can't find a reason for it to be there at all and it seems to be messing with my code. Is there anyone that knows why this is happening?
Spoiler
MasterId = 2
Modemside = "bottom"
Pass = "Pass"
AnnounceTime = 10
os.pullEvent_Real = os.pullEvent
os.pullEvent = os.pullEventRaw
function ListenRednet()
rednet.open(Modemside)
while true do
local id, msg = rednet.receive()
print(msg)
if id == MasterId then
msg = textutils.unserialize(msg)
if msg.getState then
local status = {}
status = redstone.getSides()
msg = {}
for k,v in pairs(status) do
msg[v] = {}
msg[v] = redstone.getOutput(v)
end
msg = textutils.serialize(msg)
rednet.send(id, msg)
else
if msg.state then
for k,v in pairs(msg.state) do
redstone.setOutput(k,v)
end
end
end
end
end
end
function Clear()
term.clear()
term.setCursorPos(1,1)
end
function PassTerminate()
while true do
Clear()
term.write("Enter password:")
input = read("*")
if input == Pass then
Clear()
term.write("Do you want to exit? (y/n) ")
input = read()
if input == "y" then
Clear()
os.pullEvent = os.pullEvent_Real
break
end
end
end
end
function Announce()
while true do
rednet.announce()
os.sleep(AnnounceTime)
end
end
parallel.waitForAny(ListenRednet,PassTerminate,Announce)
Spoiler
function slaveStatus(id)
if not slaves[id] then return "Invalid Id" end
local temp = {getState = true}
local msg = textutils.serialize(temp)
print(msg)
local a = rednet.send(id,msg)
if not a then return "No responce" end
msg = rednet.receive(5)
if not msg then return "No responce" end
slaves[id].state = textutils.unserialize(msg)
end
The problem lies at line 20
if msg.getState then
It throws an error as soon as it recieves the message from the sender whit a strange console outputSpoiler
I just can't find a reason for it to be there at all and it seems to be messing with my code. Is there anyone that knows why this is happening?