Jump to content




[1.3] How To Use Modems (Rednet)


  • You cannot reply to this topic
92 replies to this topic

#81 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 January 2013 - 08:57 AM

 Appleeater, on 25 January 2013 - 05:56 AM, said:

This is nice, how could I use this to send files and revive files?
You can read the file, then put it into a string, then send it over rednet. Somethign like this:
local readFile = fs.open("<filename>", "r")
local fileTab = {}
repeat
  table.insert(fileTab, readFile.readLine())
until readFile.readLine() == nil
readFile.close()

rednet.open("<side>")
rednet.send(<ID>, textutils.serialize(fileTab))
rednet.close()
That will send the file in a table, line by line.
rednet.open("<SIDE>")
local id, msg, dist = rednet.receive()
local contents = textutils.unserialize(msg)
local saveFile = fs.open("<FILENAME>", "w")
for i = 1, #contents do
  saveFile.writeLine(contents[i])
end
saveFile.close()
That should receive the file and save it.

#82 Appleeater

  • Members
  • 52 posts

Posted 25 January 2013 - 09:08 PM

 Cranium, on 25 January 2013 - 08:57 AM, said:

 Appleeater, on 25 January 2013 - 05:56 AM, said:

This is nice, how could I use this to send files and revive files?
You can read the file, then put it into a string, then send it over rednet. Somethign like this:
local readFile = fs.open("<filename>", "r")
local fileTab = {}
repeat
  table.insert(fileTab, readFile.readLine())
until readFile.readLine() == nil
readFile.close()

rednet.open("<side>")
rednet.send(<ID>, textutils.serialize(fileTab))
rednet.close()
That will send the file in a table, line by line.
rednet.open("<SIDE>")
local id, msg, dist = rednet.receive()
local contents = textutils.unserialize(msg)
local saveFile = fs.open("<FILENAME>", "w")
for i = 1, #contents do
  saveFile.writeLine(contents[i])
end
saveFile.close()
That should receive the file and save it.

Thanks is there any way I can make it save as anything from the sending pc so I could make it save as whatever I want from the sending computer


#83 UnicornForrest

  • Members
  • 3 posts

Posted 09 February 2013 - 07:24 AM

Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.

#84 HerĂ»

  • Members
  • 18 posts
  • LocationNorway

Posted 09 February 2013 - 10:37 AM

 UnicornForrest, on 09 February 2013 - 07:24 AM, said:

Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.
If you use rednet.send("..id..","..msg..") and id is 3 and msg is "Hello world!", you will send the message "..msg.." To computerid "..id.." and not the message "Hello world!" To computerid 3 (remember how you shall define variables (" shall not be used))

Use rednet.send(id,msg) (you do not need .. If you do not shall have both plain text and variables together).

#85 UnicornForrest

  • Members
  • 3 posts

Posted 09 February 2013 - 12:07 PM

 HerĂ», on 09 February 2013 - 10:37 AM, said:

 UnicornForrest, on 09 February 2013 - 07:24 AM, said:

Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.
If you use rednet.send("..id..","..msg..") and id is 3 and msg is "Hello world!", you will send the message "..msg.." To computerid "..id.." and not the message "Hello world!" To computerid 3 (remember how you shall define variables (" shall not be used))

Use rednet.send(id,msg) (you do not need .. If you do not shall have both plain text and variables together).
It still doesnt work. It keeps saying rednet:347: positive number expected.


os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
rednet.open("top")
print("Broadcast or personal message?")
input = read()
if input == "broadcast" then
 term.clear()
 term.setCursorPos(1,1)
 write("Message:")
 local msg = read()
 rednet.broadcast("'..msg..'")
 print("Sent")
 sleep(2)
 os.reboot()
elseif input == "personal" then
 term.clear()
 term.setCursorPos(1,1)
 write("To:")
 local id = read()
 write("Message:")
 local msg = read()
 rednet.send(id,msg)
 print("Sent")
 sleep(2)
 os.reboot()
end

Edited by UnicornForrest, 09 February 2013 - 12:08 PM.


#86 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 09 February 2013 - 03:31 PM

 UnicornForrest, on 09 February 2013 - 12:07 PM, said:

--snip--
You were not making the ID a number, so here is the correct code.
Spoiler


#87 UnicornForrest

  • Members
  • 3 posts

Posted 09 February 2013 - 04:08 PM

 MudkipTheEpic, on 09 February 2013 - 03:31 PM, said:

 UnicornForrest, on 09 February 2013 - 12:07 PM, said:

--snip--
You were not making the ID a number, so here is the correct code.
Spoiler
Thanks. That actually works. Now I need to make them able to receive.

#88 tommas

  • Members
  • 3 posts

Posted 13 February 2013 - 09:02 AM

Great Thanks for the help i made a password locked door and every password wrong or correct is now send to my computer!

#89 hoanganhlam

  • Members
  • 6 posts

Posted 14 February 2013 - 10:38 PM

aswesome

#90 Doyle3694

  • Members
  • 815 posts

Posted 14 February 2013 - 11:39 PM

Casper/ anyone who can edit, maybe add a note on top of the tutorial that this is not how modems work anymore?

#91 BaconHawk101

  • Members
  • 9 posts
  • LocationMy Computer

Posted 08 March 2013 - 02:44 PM

Sweet thanks man!

#92 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 08 March 2013 - 06:10 PM

 Doyle3694, on 14 February 2013 - 11:39 PM, said:

Casper/ anyone who can edit, maybe add a note on top of the tutorial that this is not how modems work anymore?

Casper hasn't been on in ages. Tbh, I've never seen him post, besides forum guidelines and whatnot.

#93 spysean1499

  • Members
  • 11 posts

Posted 16 March 2013 - 09:24 PM

dose anayone have a ftb server (for computercraft i am horrible a installing mods)with a WORKING e-mail system p.s how do i get a email system running?
thix
:) :> :X :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users