Posted 15 October 2012 - 06:00 AM
I cannot figure out why this isnt working. I got the program to work, up to where the file is sending, and i get this error. I am trying to set this up to send files over rednet. The receive code works, but the sending one doesnt yet :/ any help would be appreciated :D/>/>
Here is the sending code with the error:
And here is the working receive code:
Thanks
Here is the sending code with the error:
local args = {...}
local sides = {"top","bottom","back","front","left","right"}
for i=1,#sides do
if not rednet.isOpen(sides[i]) then
rednet.open(sides[i])
end
end
term.setCursorPos(1,1)
term.clear()
if #args < 1 then
print("Usage (<> required, [] optional):")
print("sendfile [ComputerID] <file>")
return
end
if #args == 1 then
if fs.exists(args[1]) then
textutils.slowPrint("Sending file "..args[1].."!")
rednet.broadcast("RECEIVE")
rednet.broadcast(args[1])
file = fs.open(args[1], "r")
rednet.broadcast(file.readAll())
file.close()
else
print(args[1].." does not exist!")
return
end
else
if fs.exists(args[2]) then
textutils.slowPrint("Sending file "..args[2].." to "..args[1])
F = fs.open(args[2])
id = tonumber(args[1])
rednet.send(id, "RECEIVE")
rednet.send(id, args[2])
rednet.send(id, F.readAll())
F.close()
else
print(args[2].." does not exist!")
return
end
end
And here is the working receive code:
term.clear()
term.setCursorPos(1,1)
local sides = {"left","right","top","bottom","back","front"}
for i=1,#sides do
if not rednet.isOpen(sides[i]) then
rednet.open(sides[i])
end
end
while true do
id,msg = rednet.receive()
if msg == "RECEIVE" then
id2,msg2 = rednet.receive()
f = fs.open(msg2, "w")
id3,msg3 = rednet.receive()
f.write(msg3)
f.close()
print("File "..msg2.." received!")
end
end
Thanks