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

tables help

Started by _removed, 13 February 2015 - 10:43 PM
_removed #1
Posted 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.


{
  "smigger22",
  "jasperdekiller",
}
I have no code cos its midnight
Dragon53535 #2
Posted 14 February 2015 - 12:19 AM
You need to loop through the table.


if type(message) == "table" then
  for a,v in pairs(message) do
	print(v)
  end
end
This would print out, for your table
smigger22
jasperdekiller
Edited on 13 February 2015 - 11:20 PM
_removed #3
Posted 14 February 2015 - 09:13 AM
You need to loop through the table.


if type(message) == "table" then
  for k,v in pairs(message) do
	print(v)
  end
end
This would print out, for your table
smigger22
jasperdekiller
Thats exactly what I done but it still returns table: a1b2c3d4
Dragon53535 #4
Posted 14 February 2015 - 10:24 AM
Then post your code so that I can point out your error.
Geforce Fan #5
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.
Edited on 15 February 2015 - 10:38 PM
valithor #6
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
Bomb Bloke #7
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.