Jump to content




[Lua][Question] arrays over rednet


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

#1 maddigger00009

  • New Members
  • 1 posts

Posted 30 September 2012 - 03:10 PM

can you send an array over rednet? if not can i some how send one as a string.

#2 inventor2514

  • Members
  • 63 posts

Posted 30 September 2012 - 03:19 PM

You can convert a table to a string using textutils.serialize( table )

#3 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 30 September 2012 - 03:21 PM

If you send the words separated by a space you could do
local array = {}
local id, message = rednet.receive()
for word in string.gmatch(message, "%a+") do
  table.insert(array, word)
end


#4 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 30 September 2012 - 03:28 PM

View Postinventor2514, on 30 September 2012 - 03:19 PM, said:

You can convert a table to a string using textutils.serialize( table )
And like inventor2514 mean, you can split the array/table when you send it
local array = {
  "chicken",
  "car",
  "craftComputer"
}
local sendString = ""

for _, value in pairs(array) do
  sendString = sendString + " " + value
end

string.sub(sendString, 2) -- This just removes the first 'space'

rednet.send(compId, sendString)
-- This will send:
-- chicken car craftComputer






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users