Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- function detectRedstone()
- while true do
- if rs.getInput(line) or rs.getInput(line2) then tr = "redstone" end
- sleep(0)
- end
- end
- function detectTimer()
- sleep(0)
- while true do
- os.pullEvent("key")
- tr = "timer"
- end
- end
- line = "back"
- line2 = "front"
- function send(filename)
- file = fs.open(filename, "rb")
- binary = ""
- while true do
- local a = file.read()
- if not a then break end
- binary = binary..a
- end
- file.close()
- for i=1, #binary do
- local str = binary:sub(i,i)
- if str=="1" then
- rs.setOutput(line, true)
- sleep(0.1)
- rs.setOutput(line, false)
- else
- rs.setOutput(line2, true)
- sleep(0.1)
- rs.setOutput(line2, false)
- end
- end
- end
- function mainreceive()
- file = ""
- while true do
- if tr=="" then
- sleep(0)
- else
- if tr=="timer" then break end
- if rs.getInput(line) then
- file = file.."1"
- print("1")
- end
- if rs.getInput(line2) then
- file = file.."0"
- print("0")
- end
- end
- tr = ""
- end
- end
- function receive(filename)
- print("Press any key to save the file")
- print("Receiving...")
- parallel.waitForAny(detectTimer, detectRedstone, mainreceive)
- print("breaked")
- f = fs.open(filename, "wb")
- print("Writing to file")
- for i=1, #file do
- print("x")
- local a = file:sub(i, i)
- f.write(tonumber(a))
- sleep(0)
- end
- f.close()
- end
- if #args==2 then
- if args[1]=="-send" then
- send(args[2])
- else
- receive(args[2])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement