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

Break Rednet Messages In Different Parts

Started by logsys, 16 November 2013 - 05:26 AM
logsys #1
Posted 16 November 2013 - 06:26 AM
I have a system that sends a rednet signal with ids, passwords and the action to take, and the first computer sends a rednet signal with the code

print("Please enter your ID")
idInput = read
print("Please enter you password - 4 NUMBERS ONLY")
passwordInput = read("*")
passwordInput = passwordInput/13
passwordInput = passwordInput*(1024/13)
rednet.send(serverID, "ID: " .. idInput .. " Pw: " .. passwordInput .. "checkPW")
--There is a problem but ik how to fix it
receivedID, msg = rednet.receive(60)
if receivedID == serverID then
if msg == true then
  --Stuff
else
  --stuff
end
else
receivedID, msg = rednet.receive(60)
end
in the part where in other pc it will receive this code:

"ID: " .. idInput .. " Pw: " .. passwordInput .. "checkPW"(It will NOT appear as idInput and passwordInput but yes a full msg)
I want to remove "ID: " and have receivedID = (thing after "ID: " and before " Pw: ") and receivedPw = (thingy after "Pw: ")
logsys #2
Posted 16 November 2013 - 06:41 AM
I don't feel like my title is the best for this post
jay5476 #3
Posted 16 November 2013 - 06:51 AM
try sending a serialised table

t = {pw = passwordInput,id = idInput)

create a table similar to that that suites your needs

stringVersion = textutils.serialize(t)
that gives you a string representation later to turn back to a table like this

tableVersion = textutils.unserialise(stringVersion)
so overall you would probably want something similar to this
Client

tableOfInfo = {password = password,id = I'd}
rednet.send(id,textutils.serialize(tableOfInfo))
Server

id,mes = rednet.receive()
info = textutils.unserialize(mes)
password = info["password"]
id = info["I'd"]
logsys #4
Posted 17 November 2013 - 07:19 AM
try sending a serialised table

t = {pw = passwordInput,id = idInput)

create a table similar to that that suites your needs

stringVersion = textutils.serialize(t)
that gives you a string representation later to turn back to a table like this

tableVersion = textutils.unserialise(stringVersion)
so overall you would probably want something similar to this
Client

tableOfInfo = {password = password,id = I'd}
rednet.send(id,textutils.serialize(tableOfInfo))
Server

id,mes = rednet.receive()
info = textutils.unserialize(mes)
password = info["password"]
id = info["I'd"]
Thanks, I'll try that