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

[Solved] Rednet Table Confusion

Started by JamiePhonic, 12 August 2013 - 06:25 AM
JamiePhonic #1
Posted 12 August 2013 - 08:25 AM
i'm attempting to send a serialized table with rednet, in the lua prompt i type

Sender, Message = redner.receive()
and on the lua prompt on the other computer i type:

rednet.send(2, {[1]=true,[2]="part1",[3]="Part3"})
but when i go back to the first computer and do

print(Message)
it returns as nil. am i missing something?
ZagKalidor #2
Posted 12 August 2013 - 09:22 AM
You could put the receive command inside a program and run it inside a loop, because when you do it in prompt and hit the enter key, the message is not sended yet, so there is nothing received and therefore the message is nil. The message has to be sendet in the same time the receive happens. Better would be a prog with a pull event checking for "rednet_message" , making you able to check for other event-types such as keypresses, monitor touches, mouse clicks and whatever, but you can also leave a standard loop when the message is received.

If i got that right now, there are 3 values received over rednet, not 2. SenderID, message and the distance of the sender…
JamiePhonic #3
Posted 12 August 2013 - 09:42 AM
You could put the receive command inside a program and run it inside a loop, because when you do it in prompt and hit the enter key, the message is not sended yet, so there is nothing received and therefore the message is nil. The message has to be sendet in the same time the receive happens. Better would be a prog with a pull event checking for "rednet_message" , making you able to check for other event-types such as keypresses, monitor touches, mouse clicks and whatever, but you can also leave a standard loop when the message is received.

If i got that right now, there are 3 values received over rednet, not 2. SenderID, message and the distance of the sender…
yes, however when i run
Sender, Message = redner.receive()
and on the lua prompt on the other computer i type:
rednet.send(2, "hello")
but when i go back to the first computer and do
print(Message)
it returns hello
also, because i'm not using the distance value, i don't need a variable for it

i cant see what the problem is because it works the other way. the code is for a remote auth program (server validates logins from clients)
i added debug code, when the username and password are entered, they are added to a table, which is then serialized and sent
i can see on the server that it received it, validated it then constructed a new table to send back the reply, which is another serialized table thats sent back, but this second table never seems to reach the client. i just get "attempt to concatenate string and nil" on the receive, meaning the server never sent it to begin with, hence the first post which actually explains what i did to try to see where the problem was
JamiePhonic #4
Posted 12 August 2013 - 10:29 AM
fixed it. for some reason,

local tReply = {[1]=succeed, [2]=result, [3]=username, [4]=option}
	local Reply = textutils.serialize(tReply)
	sleep(0.5)
	rednet.send(sender, Reply)
doesnt work, but

local tReply = {[1]=succeed, [2]=result, [3]=username, [4]=option}
	sleep(0.5)
	rednet.send(sender, textutils.serialize(tReply))
does. weird…
Villain #5
Posted 13 April 2014 - 01:55 AM
Just had this problem. Very odd but the fix above still works.