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

"Attempt to concatenate nil and string"

Started by Keanu, 19 December 2015 - 12:53 PM
Keanu #1
Posted 19 December 2015 - 01:53 PM
PLEASE lock this topic.
I made a turtle startup program that does other stuff, but on line 61, with code that sends GPS coordinates, it says the error message: "Attempt to concatenate nil and string"
Here's the entire code:
term.clear()
term.setCursorPos(1,1)
print("Booting Keanu&Kiwi TurtleOS")
if turtle.getItemCount() > 0 then
  turtle.drop()
end
turtle.equipLeft()
if turtle.getItemCount() > 0 then
  print("Left equipment found")
  turtle.equipLeft()
end
turtle.equipRight()
if turtle.getItemCount() > 0 then
  print("Right equipment found")
  turtle.equipRight()
end
function turtleShell()
  shell.run("shell")
end
local turtlefuel = turtle.getFuelLevel() / turtle.getFuelLimit() * 100
print("Welcome to Keanu&KiwiOS 2.0")
print("Your fuel level is: "..turtlefuel.."%")

local tModem = peripheral.find("modem")
function turtleSSH()
  tModem.open(4872)
  while true do
	e,s,c,r,m = os.pullEvent("modem_message")
	if c == 4872 and r == 5572 then
	  pcall(loadstring(m))
	end
  end
end
function turtleLocate()
while true do
  sleep(1)
  local x,y,z = gps.locate()
  if x and y and z then
	tModem.transmit(1235,1,{x = x,y = y,z = z})
  else
	tModem.transmit(1235,1,{x = "?",y = "?",z = "?"})
  end
  end
end
function turtleFuel()
  while true do
	local fuelLevelPercentage = math.floor(turtle.getFuelLevel() / turtle.getFuelLimit() * 100)
	sleep(0.1)
	os.setComputerLabel("Keanu's Mining Turtle ["..tostring(fuelLevelPercentage).."%]")
  end
end
function turtleSend()
  while true do
	sleep(1)
	if turtle.detect() then
	  tModem.transmit(4872,5572,"Obstructed")
	else
	  tModem.transmit(4872,5572,"Clear")
	end
	local x,y,z = gps.locate()
	tModem.transmit(4876,5576,"X: "..x.." | Y: "..y.." | Z: "..z.." ")
  end
end
_G.os.version = function() return "Keanu&KiwiOS 2.0" end
parallel.waitForAll(turtleSSH,turtleShell,turtleLocate,turtleFuel,turtleSend)
Edited on 19 December 2015 - 05:43 PM
TYKUHN2 #2
Posted 19 December 2015 - 03:32 PM
X or Y or Z is returning nil

Likely the gps.locate is timing out after 2 seconds.
Keanu #3
Posted 19 December 2015 - 04:02 PM
Okay.
TYKUHN2 #4
Posted 19 December 2015 - 04:16 PM
I forgot to mention the X, Y, Z on line 60 though I am sure you may have realised that…
Dragon53535 #5
Posted 19 December 2015 - 06:22 PM
You shouldn't just strikeout everything you put if your question is solved. Keep it there, and just put a note that it's solved. That way, if someone else has some kind of error near yours, and somehow stumbles on this page, they don't have to try and read through struck out code.