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

nil value

Started by Creeper9207, 21 February 2015 - 04:05 AM
Creeper9207 #1
Posted 21 February 2015 - 05:05 AM

local tArgs = { ... }
rednet.open("back")
function getlist(tdir)
-- Get all the files in the directory
local sDir = shell.dir()
if tdir ~= nil then
	sDir = shell.resolve( tdir )
end

-- Sort into dirs/files, and calculate column count
local tAll = fs.list( sDir )
local tFiles = {}
local tDirs = {}

for n, sItem in pairs( tAll ) do
	if string.sub( sItem, 1, 1 ) ~= "." then
		local sPath = fs.combine( sDir, sItem )
		if fs.isDir( sPath ) then
			table.insert( tDirs, sItem )
		else
			table.insert( tFiles, sItem )
		end
	end
end
table.sort( tDirs )
table.sort( tFiles )
	a = textutils.pagedTabulate( colors.green, tDirs, colors.white, tFiles)
	rednet.broadcast(a, ":ftp:text", "incoming")
end
function transferFile(xFile)
if fs.exists(xFile) then
z = fs.open(xFile, "r")
y = z.readAll()
z.close()
rednet.broadcast(y .. ":ftp:fileincoming", "incoming")
else
x = "file does not exist"
rednet.broadcast(x .. ":ftp:text", "incoming")
end
end
function recieveFile(mFile)
g = string.match(mFile, "(%b<>)")
g = string.gsub(g, "<", "")
g = string.gsub(g, ">", "")
print(g)
uFile = mFile:gsub("<" .. g .. ">", "")
ow, err = fs.open(g, "w")
print(err)
ow.write(uFile)
ow.flush()
ow.close()
print(g .. " " .. mFile)

end
recieveFile("<hi>Hello")
while true do
senderID, msg, dis, protocol = rednet.receive("outgoing", 50)
end



Line of code erroring for NO REASON
error: attemp to index ? a nil value
Edited by
safetyscissors #2
Posted 21 February 2015 - 05:08 AM
is the uFileFile a typo? or legit on line 5
Creeper9207 #3
Posted 21 February 2015 - 05:31 AM
neither, it was notepad++ being notepad++
Bomb Bloke #4
Posted 21 February 2015 - 05:57 AM
Line of code erroring for NO REASON

Rather, it's erroring because you're attempting to have it index into a variable that's set to nil - as opposed to being set to point to a table.

It'd be easier to explain the specifics if you provided the full error - there should be a line number in there somewhere.