Posted 17 May 2013 - 02:00 AM
                Hello Pros
I know you've probably answered lots of questions about sending tables but I really can't figure this out. I'm trying to make a program for wireless mining turtles. I want a computer to be able to send commands and receive messages to/from the turtle. One of the things I want the computer to do is ask for the turtle's status in the form of a table that it will print.
Here are the functions for sending the table from the turtle:
this is the computer's function for getting the status:
No errors come up, tStatus just seems to be nil so the monitor does not print the tests…
If someone could kindly tell me what I am doing wrong that would be greatly apreciated.
                
            I know you've probably answered lots of questions about sending tables but I really can't figure this out. I'm trying to make a program for wireless mining turtles. I want a computer to be able to send commands and receive messages to/from the turtle. One of the things I want the computer to do is ask for the turtle's status in the form of a table that it will print.
Here are the functions for sending the table from the turtle:
local function getStatus()
  local x, y, z = gps.locate(4)
  if not x then
	x, y, z = "Could not locate", "Could not locate", "Could not locate"
   end
  -- local fuel = turtle.getFuelLevel()
  stage = "Testing"					-- this was so that I was sure it had a value
  local inv_room = 0
  for i = 4, 9 do
	inv_room = inv_room + turtle.getItemSpace(i)
  end
  local tStatus = { blocks_mined, stage, inv_room, x, y, z }
return tStatus
end
local function receive()
  while true do
	local sender, message, distance = rednet.receive()
	if sender ~= monitorID then
	  rednet.send(sender, "You are not my monitor!")
   end
	if message == "CheckStatus" then
	 local Status = getStatus()
	 print("Serialising and sending")
	 local sStatus = textutils.serialize(Status)		   -- these seem to run fine, they don't come up
	 rednet.send(monitorID, sStatus, true)			  -- with any errors at all
	 for key, value in ipairs(Status) do print(key..": "..value) end  -- this does not even print, so the
                                             --problem is with getStatus() I'm sure...
  elseif message == "StopMining" then
	 rednet.send(monitorID, "Stopping")
	 command = 2
  break
  else rednet.send(monitorID, "Unknown command")
  end
  end
  return
end this is the computer's function for getting the status:
local function askForStatus()
  print("Asking for status...")
  rednet.send(turtleID, "CheckStatus", true)
  senderID, sStatus, distance = rednet.receive()
  if senderID ~= turtleID then
	rednet.send(senderID, "You are not my turtle!")
  end
  if not sStatus then
	print("Status could not be retrieved.")
	return false
  elseif sStatus then
	print("Status was retrieved. Unserialising...")
	tStatus = textutils.unserialize(sStatus)
  end
  print("tStatus: "..tStatus)
  if tStatus then
	print("A table was received")			 -- these two tests don't print...
  end
	-- for key, value in ipairs(tStatus) do print(key..": "..value) end  
end No errors come up, tStatus just seems to be nil so the monitor does not print the tests…
If someone could kindly tell me what I am doing wrong that would be greatly apreciated.
 
         
                