Jump to content




tables help


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

#1 _removed

  • Members
  • 262 posts

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

#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

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 by Dragon53535, 14 February 2015 - 12:20 AM.


#3 _removed

  • Members
  • 262 posts

Posted 14 February 2015 - 09:13 AM

View PostDragon53535, on 14 February 2015 - 12:19 AM, said:

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

#4 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 February 2015 - 10:24 AM

Then post your code so that I can point out your error.

#5 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 15 February 2015 - 11:35 PM

I already know your error.
Posted Image
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 by Geforce Fan, 15 February 2015 - 11:38 PM.


#6 valithor

  • Members
  • 1,053 posts

Posted 16 February 2015 - 12:02 AM

View PostGeforce Fan, on 15 February 2015 - 11:35 PM, said:

-snip

Rednet actually automatically serializes the message for you, so you do not have to.

Edited by valithor, 16 February 2015 - 12:12 AM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users