{
"smigger22",
"jasperdekiller",
}
I have no code cos its midnight
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
tables help
Started by _removed, 13 February 2015 - 10:43 PMPosted 13 February 2015 - 11:43 PM
I have a computer sending stuff through rednet. It is in a table and I dont know to make it print all values. This is an example of what it would be sending.
Posted 14 February 2015 - 12:19 AM
You need to loop through the table.
smigger22
jasperdekiller
if type(message) == "table" then
for a,v in pairs(message) do
print(v)
end
end
This would print out, for your tablesmigger22
jasperdekiller
Edited on 13 February 2015 - 11:20 PM
Posted 14 February 2015 - 09:13 AM
Thats exactly what I done but it still returns table: a1b2c3d4You need to loop through the table.This would print out, for your tableif type(message) == "table" then for k,v in pairs(message) do print(v) end end
smigger22
jasperdekiller
Posted 14 February 2015 - 10:24 AM
Then post your code so that I can point out your error.
Posted 15 February 2015 - 11:35 PM
I already know your error.
When you send your message, instead of sending the table, send this:
textutils.serialize(table)
Then when receiving it, do:
table=textutils.unserialize(table)
To explain this, you can only send strings over rednet. Serializing converts a table into a string, and unserializing converts a serialized table(string) into a table.
You CANNOT, however, send functions over rednet.
When you send your message, instead of sending the table, send this:
textutils.serialize(table)
Then when receiving it, do:
table=textutils.unserialize(table)
To explain this, you can only send strings over rednet. Serializing converts a table into a string, and unserializing converts a serialized table(string) into a table.
You CANNOT, however, send functions over rednet.
Edited on 15 February 2015 - 10:38 PM
Posted 16 February 2015 - 12:02 AM
-snip
Rednet actually automatically serializes the message for you, so you do not have to.
Edited on 15 February 2015 - 11:12 PM
Posted 16 February 2015 - 01:24 AM
It depends on which version of ComputerCraft you're using. Anything even half recent will indeed handle it for you.
smigger22 could be trying to capture the rednet_message event, or making a number of other mistakes. Can't really say for sure without seeing the code.
smigger22 could be trying to capture the rednet_message event, or making a number of other mistakes. Can't really say for sure without seeing the code.