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

Textutils/Sending Tables Through Rednet

Started by Mr_Programmer, 26 June 2017 - 09:50 PM
Mr_Programmer #1
Posted 26 June 2017 - 11:50 PM
Hey,

long story short, im wanting to insert some code into a table from one program and send it to another program
this is how my table is being set up


serverUsage = "Quarantine Test"

local dataDump = {}

if Modemtest == true then
  term.clear()
  term.setCursorPos(1,1)
  print("Please Enter The Servers Information")
  local w,h = term.getSize()
  term.setCursorPos(math.floor(w-#"Server ID:")/2-5,3)
  print("Server ID:")
  term.setCursorPos(math.floor(w-#"Server Sync Code:")/2-2,5)
  print("Server Sync Code:")
  term.setCursorPos(math.floor(w+#"Server ID:")/2-5,3)
  servID = io.read()
  term.setCursorPos(math.floor(w+#"Server Sync Code:")/2-2,5)
  servSyncCode = io.read()

	term.setCursorPos(1,8) --testing purposes
	print(servID) --testing purposes
	term.setCursorPos(1,9) --testing purposes
	print(servSyncCode) --testing purposes

	--dataSendServerUsage = tonumber(serverUsage)
	  table.insert(dataDump, 1, servSyncCode)
	  table.insert(dataDump, 2, serverUsage)
	  dataSend = textutils.serialize(dataDump)

	   rednet.send(tonumber(servID), dataDump)

so from my understanding servSyncCode is a read variable resulting in a string and serverUsage is a string variable
so after running it should look like this if im correct
 local dataDump = {"whatever the user entered", "Quarantine Test"}

Now what the user entered should be a number so if i converted it to a number instead of a string then it should look like this

 local dataDump = {225554444, "Quarantine Test"}

now for the other program that recieves the table

randomCodeGen = math.random(100000000,999999999) --gen a random number
	table.insert(syncCodeStorage, randomCodeGen) -- inserts the random number to a temp table
	print(syncCodeStorage[1]) --prints the random number so the user knows what it is
syncLoop = true
  while syncLoop == true do
   local event, ID, syncData = os.pullEventRaw()
	if event == "rednet_message" then  -- waiting for a rednet event
	 local dataCache = textutils.unserialize(syncData) -- unserialize the table that was serialized from the other program and sent
	  if tonumber(dataCache[1]) == syncCodeStorage[1] then --compairing the first key of the sent table which should be 225554444 to the random number that was generated
	   rednet.send(ID, "CorrectSyncCode")
	  else
	   rednet.send(ID, "IncorrectSyncCode")
	  end
	end
  end

everytime the while loop is ran, once it gets a rednet message i get the error

"Textutils:304: attempt to concatenate string and table"

Can someone point out where im going wrong, hope there is enough detail and isnt to cinfusing for you

Thanks, MrProgrammer
Edited on 26 June 2017 - 10:03 PM
Bomb Bloke #2
Posted 27 June 2017 - 12:17 AM
dataSend = textutils.serialize(dataDump)            --# Serialises "dataDump" table into "dataSend".

           rednet.send(tonumber(servID), dataDump)  --# Ignores "dataSend" and transmits the "dataDump" table.
Dog #3
Posted 27 June 2017 - 12:18 AM
I haven't reviewed your code thoroughly, so I don't know if this will address your error message, but I do see a couple of problems:

1. You want to send dataSend not dataDump as you are doing now.

2. In the places where you are trying to center text, you are math.flooring whole numbers instead of math.flooring your division over two. This has nothing to do with your error message, but you should get better results by flooring the result of the division rather than converting an already whole number to a whole number.

EDIT: :ph34r:/> 'd by BB
Edited on 26 June 2017 - 10:20 PM
Mr_Programmer #4
Posted 27 June 2017 - 12:26 AM
dataSend = textutils.serialize(dataDump)			--# Serialises "dataDump" table into "dataSend".

		   rednet.send(tonumber(servID), dataDump)  --# Ignores "dataSend" and transmits the "dataDump" table.

<_</> Asif i didnt see this, it is 1am and have been up for 18hours :lol:/>

I haven't reviewed your code thoroughly, so I don't know if this will address your error message, but I do see a couple of problems:

1. You want to send dataSend not dataDump as you are doing now.

2. In the places where you are trying to center text, you are math.flooring whole numbers instead of math.flooring your division over two. This has nothing to do with your error message, but you should get better results by flooring the result of the division rather than converting an already whole number to a whole number.

EDIT: :ph34r:/> 'd by BB
Yeah i know, i was playing around with the math.floor, the text isnt really centered i have a function that really centers the text
SquidDev #5
Posted 27 June 2017 - 09:30 AM
I'm pretty sure you don't need to serialise the table when sending it. For instance, rednet just sends a raw table. This allows you to have send recursive data structures too, which is always nice.
Edited on 27 June 2017 - 07:30 AM
Mr_Programmer #6
Posted 27 June 2017 - 01:46 PM
I'm pretty sure you don't need to serialise the table when sending it. For instance, rednet just sends a raw table. This allows you to have send recursive data structures too, which is always nice.

What do you mean by recursive data?
KingofGamesYami #7
Posted 27 June 2017 - 01:55 PM

t = { "Hello" }
t.t = t
print( t.t.t.t.t.t.t.t.t.t.t[1] )