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

Unpack return nil

Started by loustak, 23 July 2016 - 10:25 PM
loustak #1
Posted 24 July 2016 - 12:25 AM
Hello,
I'm using computer craft for minecraft 1.7.10.
I got this :

function var.Pos:load(data)
        print(data.x) -- Print "2" as excepted
        foo = unpack(data)
        print(type(foo)) -- Print nil
	    print(foo.x) -- Error of course
end
Second try :

function var.Pos:load(data)
        print(data.x) -- Print "2" as excepted
        foo = table.unpack(data) -- Modification here
        print(type(foo)) -- Print nil
	    print(foo.x) -- Error of course
end
I don't understand why foo isn't filled with anything here…
Thanks for the help !
Emma #2
Posted 24 July 2016 - 12:35 AM
In cc Lua table.unpack doesn't work, also unpack unpacks ONLY the tables contents which are numerically indexed in sequential order for example if there are keys 1, 2, and 4, only 1 and 2 will be unpacked

Edit: Aparently table.unpack seems to work now, strange, I remember it being broken at one point.
Edited on 23 July 2016 - 10:43 PM
KingofGamesYami #3
Posted 24 July 2016 - 01:03 AM
Edit: Aparently table.unpack seems to work now, strange, I remember it being broken at one point.

It was added with Lua 5.2 - actually, in some cases unpack is removed in favor of table.unpack.
loustak #4
Posted 24 July 2016 - 08:28 AM
Thanks for the help, the problem was the sequential order !