Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unknown Table Stuff?

Asked by
Hibobb 40
10 years ago

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

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

0
Whats the wiki link? It should tell you what kind of table it is. MessorAdmin 598 — 10y
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] = { Hibobb 40 — 10y

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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.

0
So how do you create tables inside of tables? Just bricks[1] = colors{} somthing like that? Hibobb 40 — 10y
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? adark 5487 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
-- 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.

Answer this question