This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SpencerBeige's profile picture

help

Started by SpencerBeige, 15 November 2014 - 01:27 AM
SpencerBeige #1
Posted 15 November 2014 - 02:27 AM
trying to send a table thru rednet…no wurk plz help. i cannot access the file, as i am on a server. so…how do i use rednet.broadcast() and rednet.receive() to send, and receive a table?
Dragon53535 #2
Posted 15 November 2014 - 02:33 AM

local tbl = {"I'm a table!"}
rednet.open("left") --#Let's say the modem is on the left
rednet.broadcast(tbl,"Myprotocol")

rednet.open("left")
local senderID, message, protocol = rednet.receive(0,"Myprotocol") --#Only messages with the protocol Myprotocol will allow the program to continue
print(message[1]) --#I'm a table!
Edited on 15 November 2014 - 01:35 AM
Lyqyd #3
Posted 15 November 2014 - 02:46 AM
Which version of CC are you using?
Dragon53535 #4
Posted 15 November 2014 - 03:05 AM
I'm assuming by his post in LuaLand's topic, he's on 1.65 or 1.63, i think 1.65 i just don't know what version's on the mod pack :P/>
valithor #5
Posted 15 November 2014 - 03:08 AM
I'm assuming by his post in LuaLand's topic, he's on 1.65 or 1.63, i think 1.65 i just don't know what version's on the mod pack :P/>

It is 1.65
SpencerBeige #6
Posted 15 November 2014 - 04:36 PM
this is pretty much what im doing, im doing something like this(btw, im making an online bank system, so plz dont question whats inside the table):

m = {"newuser", username, pin}

rednet.broadcast(m, ATM)
———————————————————————————-
m = rednet.receive(ATM)

for i = 1,#m do
print(m)
end
————————————————————————————-

and this is pretty much what i get back:
1279(computer id#)
table:(random nums and letters)
ATM
valithor #7
Posted 15 November 2014 - 04:53 PM
this is pretty much what im doing, im doing something like this(btw, im making an online bank system, so plz dont question whats inside the table):

m = {"newuser", username, pin}

rednet.broadcast(m, ATM)
———————————————————————————-
m = rednet.receive(ATM)

for i = 1,#m do
print(m)
end
————————————————————————————-

and this is pretty much what i get back:
1279(computer id#)
table:(random nums and letters)
ATM

Put "" around atm. Right now you are setting the protocol to a variable which equals nil, which I would assume would make it assume that there is not a protocol.

edit:
You are probably intercepting someone elses rednet message asusming you are still on a server.
edit2:
Just saw you are getting the protocol back when you receive the msg.
Edited on 15 November 2014 - 03:58 PM
SpencerBeige #8
Posted 15 November 2014 - 05:14 PM
i tried putting "" around the protocol; still no wurk. also, i do agree that in autumncity, it is a big problem. people are setting up robots that send messages to every computer, it makes me angry since they are effectively making rednet 10x harder to work with
Dragon53535 #9
Posted 15 November 2014 - 06:00 PM
i tried putting "" around the protocol; still no wurk. also, i do agree that in autumncity, it is a big problem. people are setting up robots that send messages to every computer, it makes me angry since they are effectively making rednet 10x harder to work with
Your problem is that you're not looking inside the table… You're just looking at it…


print(message[1]) --# "newuser"
print(message[2]) --# username
print(message[3]) --# pin
MKlegoman357 #10
Posted 15 November 2014 - 08:22 PM
rednet.receive() returns the sender's ID, then the message and then the protocol (if there was one). You are only catching the ID and trying to iterate through that.
Bomb Bloke #11
Posted 15 November 2014 - 10:40 PM
Given the stated output, I guess he used m = {rednet.receive()}, but didn't reflect that in the code he showed.
Dragon53535 #12
Posted 16 November 2014 - 12:11 AM

local message = m[2] --#Turn message into the table held in m[2]
print(message[1]) --# Your newuser thing
print(message[2]) --# Their username
print(message[3]) --# Their pin