Posted 11 July 2014 - 03:33 PM
Hi guys today it is a difficult thing I mostly have it done:
So I have created custom main computer and I am forcing connection to that computer from the repeat program.
So the pc sends a message to the repeat program then the repeat program sends that message to the main PC in wich it decrypts the message and sends it to the owner and logs the decrypted message. The problem I am having is that the message that is sent from the repeat program is actually a table and I was wondering how do I get the actual message from that table here is an example on how I want to do it:
Code:
Output:
So that's how I wanna do it. I need the message from the table before the senderDistance.
How do I know it is a table? This is inside the repeat program:
Solution:
But we want to capture it so we use this code:
Now you may be wondering why just not do:
local message = msg.message
well the reason for that is the message is a table not a string so what we need to do is the following:
Final Code:
Hope it fixes the problem for you :D/> I tried my best to explain it
Thanks.
So I have created custom main computer and I am forcing connection to that computer from the repeat program.
So the pc sends a message to the repeat program then the repeat program sends that message to the main PC in wich it decrypts the message and sends it to the owner and logs the decrypted message. The problem I am having is that the message that is sent from the repeat program is actually a table and I was wondering how do I get the actual message from that table here is an example on how I want to do it:
Code:
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
local msg = decrypt(message.message()) -- IDK what it is here
print(msg)
Output:
Spoiler
this is a messageSo that's how I wanna do it. I need the message from the table before the senderDistance.
How do I know it is a table? This is inside the repeat program:
if type( tMessage ) == "table" and tMessage.nMessageID and tMessage.nRecipient then
Solution:
Spoiler
What I did was I checked how rednet handles messages and I came across this:
local tMessage = {
nMessageID = nMessageID,
nRecipient = nRecipient,
message = message,
sProtocol = sProtocol,
}
The table is then sent to the id specified here:
peripheral.call( sModem, "transmit", nRecipient, nReplyChannel, tMessage );
So when we type the message it is saved in a table called tMessage as message so that table gets sent over rednet to the computer.But we want to capture it so we use this code:
modem.open(os.getComputerID())
local event, modemSide, senderChannel, replyChannel, msg = os.pullEvent("modem_message")
That will receive the message table and put it inside the msg variable. With that done we still have some work to do.Now you may be wondering why just not do:
local message = msg.message
well the reason for that is the message is a table not a string so what we need to do is the following:
local message = "" -- This will create a simple string where the message will be put
if type( msg.message ) == "table" then -- We have to make sure that the message is a table!
for i, v in pairs(msg.message) do -- we go through the message table
message = message.." "..v -- we write the line from the table to message
end -- And we are done
else -- If it is not a table
message = msg.message -- Just put it inside the message
end
What that does is it checks if the msg.message is a table and if it is then we loop through the table and put the message tougether but if it is not then just put the message as it is.Final Code:
local event, modemSide, senderChannel, replyChannel, msg = os.pullEvent("modem_message")
local message = ""
if type( msg.message ) == "table" then
for i, v in pairs(msg.message) do
message = message.." "..v
end
else
message = msg.message
end
Hope it fixes the problem for you :D/> I tried my best to explain it
Thanks.
Edited on 12 July 2014 - 12:55 PM