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

bad argument: table expected, got nil

Started by Baddawg0509, 03 April 2015 - 12:53 PM
Baddawg0509 #1
Posted 03 April 2015 - 02:53 PM
I am getting this error "48: bad argument: table expected, got nil" when I run my program. I am trying to use the program from the Direwolf20 let's play series to sort the aspect names at this point. Here is a link to the code http://pastebin.com/n3KumTsr or line 3 from this snippet

function sortEss(t)
   local keys = {}
   for k in pairs(t) do keys[#keys+1] = k end
   table.sort(keys)
  
   local i = 0
   return function()
	  i = i+1
	  if keys[i] then
		 return keys[i], t[keys[i]]
	  end
   end
end


Any help would be greatly appreciated! Thank you in advance!
Possseidon #2
Posted 03 April 2015 - 03:47 PM
As far as I see you never gave t, which you pass in your function, a value. That's why pairs(t) complains about t being nil.
ItsRodrick #3
Posted 03 April 2015 - 03:58 PM
Change line 88 to
sortEss(ess)

Should work…
Baddawg0509 #4
Posted 03 April 2015 - 04:15 PM
Change line 88 to
sortEss(ess)

Should work…

This fixed it! Thank you for the quick response guys!