If AmenMoses and smallg don't mind I would like to give my understanding using terminology I have always used with various programming languages that include BASIC, Pascal, C, Visual Basic and Visual Basic 6, C++, COBOL, and Assembly Language. The ability to have tables/matrices in Lua is referred to as arrays within the official documentation. So, that is why I like to use the terminology of arrays.
Arrays are ordered arrangements of objects, which can have one-dimensionality containing a collection of rows or a multi-dimensionality containing multiple rows and columns.
In Lua, arrays are implemented using indexing tables with integers. A one-dimensional array can be represented using a simple table structure and can be initialized and read using a simple for loop.
array = {"Lua", "Tutorial"}
for i = 0, 2 do
--print(array[i])
TextCenterOnX(x,Line,fontsize,array[i])
Line = Line + 5
end
--[[
The above code will yield the following:
nil
Lua
Tutorial
]]
When trying to access an element in an index that is not actually there, it returns nil. In Lua, indexing generally starts at index 1. But, it is possible to create objects at index 0 and even below 0 as well, I would suggest to always use "1" as the start index.
OK, let's now look at multi-dimensional arrays. These can be implemented in two ways.
* Array of arrays
* Single dimensional array by manipulating indices
I'm only going to look at an array using "array of arrays."
-- Initializing the array
array = {}
for i=1,3 do
array[i] = {}
for j=1,3 do
array[i][j] = i*j
end
end
-- Accessing the array
for i=1,3 do
for j=1,3 do
print(array[i][j])
end
end
--[[
--Again, "print" is not a command found in GG but I am using it as a visual representation for reading the array. This will yield the following output.
1
2
3
2
4
6
3
6
9
]]
So, g_Entity[e]['health'], g_Entity[e]['angley'], and g_Entity[e]['x'] are examples of multi-dimensional arrays using "array of arrays".
Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory