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

Attempt To Index ? (a Nil Value)

Started by deFENCE_, 02 November 2013 - 04:58 AM
deFENCE_ #1
Posted 02 November 2013 - 05:58 AM
I've been working on a program that builds schematic-like stuff. Here's the code.




Spoiler

local args = {...}

if #args ~= 4 then
  print("Usage: build <file> <x> <y> <z>")
  exit()
end

local file = args[1]
local x = args[2]
local y = args[3]
local z = args[4]

sfile = fs.open(file, "r")
Instructions = split(sfile.readAll(), ",")
if Instructions == nil then
  print("Instructions file is corrupt or empty")
  exit()
end

--shell.run("goto", x, y, z)

for i = 1, #Instructions do
  local slot = tonumber(split(Instructions[i], "#")[1])
  local coords = split(split(Instructions[i], "#")[2], ";")[1]
  local bx = currentX + coords[1]
  local by = currentY + coords[2]
  local bz = currentZ + coords[3] + 1

  shell.run("goto", bx, by, bz)
  turtle.select(slot)
  turtle.placeDown()
end

--shell.run("goto", x, y, z)

function split(pString, pPattern)
  if sep == nil then
    sep = "%s"
  end
  local t = {}
  local i = 1
  for str in string.gmatch(pString, "([^"..pPattern.."]+)") do
    t[i] = str
    i = i + 1
  end
  return t
end
It always throws an error when I type in the foolowing command:

build house.cs -118 65 23
It says:
build_cs:6: attempt to index ? (a nil value)
But at line 6 there is only the
end
What is also wierd, there is no build_cs file on my turtle :/
It WAS named build_cs but now it's named build
Please help me!
sens #2
Posted 02 November 2013 - 06:03 AM
What is also wierd, there is no build_cs file on my turtle :/
It WAS named build_cs but now it's named build
Is the turtle next to a disk drive, by any chance?
deFENCE_ #3
Posted 02 November 2013 - 06:14 AM
No it isn't.
LBPHacker #4
Posted 02 November 2013 - 06:32 AM
Well, whatever, believe it or not, that error actually points to the file called build, and occurs because exit is nil. Use the return keyword.

EDIT: I still have no idea how loadstring got something like "build_cs"…
deFENCE_ #5
Posted 02 November 2013 - 06:50 AM
Well, whatever, believe it or not, that error actually points to the file called build, and occurs because exit is nil. Use the return keyword.
exit() has always worked… well whatever. I'll try
deFENCE_ #6
Posted 02 November 2013 - 07:12 AM
Well, whatever, believe it or not, that error actually points to the file called build, and occurs because exit is nil. Use the return keyword.

EDIT: I still have no idea how loadstring got something like "build_cs"…
Idk, when i had that, i pastebin'd the file and downloaded it again. same thing with build_cs. Anyway, thx for helping