Talk:Tables

From Legacy Roblox Wiki
Jump to navigationJump to search

This is copyrighted material and should be deleted in favor of a reference. --GoldenUrg 19:01, 24 April 2010 (UTC)

Maybe we should just do a rollback? --Blocco 20:05, 24 April 2010 (UTC)
It was that way from the beginning. The alternative is to write a more basic/beginner description here and reference Lua/pil for the more advanced details. --GoldenUrg 22:05, 24 April 2010 (UTC)

rewrite

Thinking I'll rewrite this to be more applicable to Roblox (i.e, explain methods that return tables) and actually explain how to use the Lua 5.1 table libraries. --Samacado 17:25, 16 December 2010 (UTC)

You may use the article here: http://wikilua.wikia.com/wiki/Table CamoyContribs (December 18 2010)

@SDuke: "Added that anything can be used as an index"

diff

Yes, it can, but your code won't work. Try running this code:

local t = {}
t[Vector3.new(1,2,3)] = true
print(t[Vector3.new(1,2,3)])  --nil!

And compare it to this:

local t = {}
local v = Vector3.new(1,2,3)
t[v] = true
print(t[v])  --true!

The problem is that table keys are checked by reference. While Vector3.new(1,2,3) == Vector3.new(1,2,3)</syntaxhighlight>, they do not refer to the same object: i.e., their references are not equal. This means they are treated as unique table keys, which is undesireable.

For more info, see the "Keys are references" section of the lua Tables Tutorial.

21:12, 7 August 2011 (UTC)