Jump to content




Break Rednet Messages In Different Parts


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

#1 logsys

  • Members
  • 171 posts

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: ")

#2 logsys

  • Members
  • 171 posts

Posted 16 November 2013 - 06:41 AM

I don't feel like my title is the best for this post

#3 jay5476

  • Members
  • 289 posts

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"]


#4 logsys

  • Members
  • 171 posts

Posted 17 November 2013 - 07:19 AM

View Postjay5476, on 16 November 2013 - 06:51 AM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users