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

Error: Pocket computer error

Started by FireGoldsky, 04 April 2015 - 03:55 PM
FireGoldsky #1
Posted 04 April 2015 - 05:55 PM
So, I was writing (mostly copying) a program, frame, for my advanced pocket computer. Right now, im getting the following error: "frame:36: attempt to concatenate string and nil".
The code is the following:

rednet.open("back")
os.loadAPI("button")
local m = term
local menuType = "mainMenu"
local mainCompID = 0
local frameCompID = 6
local frameCoords = {}
frameCoords["x"] = 0
frameCoords["y"] = 0
frameCoords["z"] = 0
function sendMessage(message)
	rednet.send(mainCompID, message)
end
function mainMenu()
m.clear()
button.clearTable()
button.setTable("Up", frameMove, "Up", 3, 13, 1, 1)
button.setTable("Down", frameMove, "Down", 15, 25, 1, 1)
button.setTable("Forward", frameMove, "Forward", 3, 13, 3, 3)
button.setTable("Backward", frameMove, "Backward", 15, 25, 3, 3)
button.setTable("Bedrock", textMessage, "Bedrock", 3, 13, 5, 5)
button.setTable("SeaLevel", textMessage, "SeaLevel", 15, 25, 5, 5)
button.setTable("SendItems", textMessage, "SendItems", 3, 13, 7, 7)
-- button.setTable("Dome", textMessage, "Dome", 15, 25, 7, 7)
button.setTable("Cycle", textMessage, "Cycle", 15, 25, 7, 7)
button.setTable("NextCycle", textMessage, "NextCycle", 15, 25, 9, 9)
button.setTable("AutoMode", textMessage, "AutoMode", 3, 13, 13, 13)
button.setTable("STOP", textMessage, "STOP", 15, 25, 13, 13)
button.setTable("Refresh Coords", setFrameCoords, "", 3, 25, 17, 17)
button.label(1,20,"Frame Coords: "..frameCoords["x"]..","..frameCoords["y"]..","..frameCoords["z"])
checkCurrentFunction()
button.screen()
end
function getFrameLoc()
local data = {}
local id,msg,proto
repeat
  rednet.send(frameCompID, "GPS")
  id,msg,proto = rednet.receive(0.1)
until id == frameCompID
data = textutils.unserialize(msg)
return data["x"], data["y"], data["z"]
end
function setFrameCoords()
button.toggleButton("Refresh Coords")
frameCoords["x"], frameCoords["y"], frameCoords["z"] = getFrameLoc()
button.toggleButton("Refresh Coords")
end
function frameMove(message)
--button.toggleButton(message)
local data = {}
data[0] = "moveFrame"
data[1] = message
sendMessage(textutils.serialize(data))
--waitComplete()
--button.toggleButton(message)
end
function textMessage(message)
local data = {}
data[0] = message
sendMessage(textutils.serialize(data))
end
function checkCurrentFunction()
local id,msg,proto
repeat
  textMessage("CurrentFunction")
  id,msg,proto = rednet.receive(0.1)
until msg
data = textutils.unserialize(msg)
if data[0] ~= "" then
  button.setButton(data[0], true)
end
button.setButton("AutoMode", data[1])
button.setButton("Cycle", data[2])
end
function displayScreen()
-- setFrameCoords()
mainMenu()
local timerCode = 0
timerCode = os.startTimer(1)
local event,side, x, y
repeat
-- event, side, x, y = os.pullEvent("mouse_click")
event, side, x, y = os.pullEvent()
-- print(event)
-- sleep(0.2)
-- print(event..":"..side)

until side == timerCode or event=="mouse_click" or event == "mouse_drag"
if event == "mouse_click" or event == "mouse_drag" then
  os.cancelTimer(timerCode)
  button.checkxy(x,y)
end
end
while true do
displayScreen()
end
(…) and the problem seems to be around here:

local id,msg,proto

I searched in the forums and youtube, etc, but couldn't find a solution, therefore I think ther best is to Ask a Pro!
Thank you!
Edited on 04 April 2015 - 05:06 PM
HPWebcamAble #2
Posted 04 April 2015 - 06:56 PM
Line 36 for the code you posted is this:

local id,msg,proto

Make sure you copy and paste your exact code so that the line numbers will match up
Edited on 04 April 2015 - 04:56 PM
FireGoldsky #3
Posted 04 April 2015 - 07:06 PM
Line 36 for the code you posted is this:

local id,msg,proto

Make sure you copy and paste your exact code so that the line numbers will match up
Oh, sorry, copy paste error!
HPWebcamAble #4
Posted 04 April 2015 - 07:23 PM
Oh, sorry, copy paste error!

Are you sure this is the exact code?

Line 36 shouldn't be able to throw that error
Bomb Bloke #5
Posted 04 April 2015 - 11:22 PM
The only concatenation you are performing anywhere near line 36, and indeed, within the whole script, is on line 30:

button.label(1,20,"Frame Coords: "..frameCoords["x"]..","..frameCoords["y"]..","..frameCoords["z"])

So let's assume that's the one throwing your error.

The way I see it, the only way frameCoords.x/y/z can be nil is if the "GPS" system you communicate with in your getFrameLoc() function (executed when people press the "Refresh Coords" button) sends an invalid message. You might want to post the rest of the code involved here.

If, on the other hand, the script crashes on launch, then I'd be inclined to say that the script you've pasted is not the script you're actually running - which sounds quite likely, given the line-number mix-up.