Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unknown Table Stuff?

I stumbled upon this in a Roblox wiki or something. What does it mean?

array[16][12] of 16-bit intergers

2 comments

0

Whats the wiki link? It should tell you what kind of table it is.

0

I actually just went back and searched for it and it was in a script. Heres the line(it goes on to define things in the table, but I can not figure out based on what its defining): Cells[x][y] = {

2 answers

✓ Accepted answer

Brackets are the "actual" access operators in Lua.

The dot . access operator is typically used in place of string-indexes with the brackets:

Table.thing
--is equivalent to
Table["thing"]

What that code is doing is using the array Table, and accessing the 16th member of that, which is also a Table, and then accessing the 12th member of it.

2 comments

0

So how do you create tables inside of tables? Just bricks[1] = colors{} somthing like that?

0

You have to think of Tables as any other data type. How do you set a variable to a number? How do you set a variable to a Table? How do you set a Table member to a number?

-- Simple version: 
local array = {}
array[16] = {}
array[16][12] = 255
-- Common version:
local array = {}
for n=1,16 do
	array[n] = {}
end
array[16][12] = 255
-- Simple type declaration:
Array2 = {
	new = function(rows,columns)
		local array = {}
		for x=1,rows do
			array[x] = {}
			for y=1,columns do
				array[x][y] = 0
			end
		end
		return array
	end,
}
array = Array2.new(16,12)
array[16][12] = 255

By the way, a "array[16][12]" is a 2-dimensional array (grid) with the dimensions 16,12 (Like the code above shows: A table with 16 elements, with the value of every element set to another table with 12 elements, with the value of every element set to 0. Lua however doesn't make a difference between ints, float, doubles or bytes. In Lua these are all called "numbers", and thus a array[16][12] of 16-bit integers is basicly a array[16][12] of numbers, with all default values set to full numbers between 0 and 65535, and assuming you will not set any value that's not a full number or is below 0/above 65535.

This discussion is preserved as it was. New answers, comments, and votes are closed.