[] and . aren't very distinct in Lua, because tables are so flexible (they are used for what would be both arrays and structs in C++). For example, in Lua, table["key"] is the same as table.key. The only reason to use one over the other is if you use a variable that holds the key.
Code:
-- I know the name of the property
local val1 = table.property
-- The name of the property is stored in a variable
local propertyname = "property"
local val2 = table[ propertyname ]
In C++, there is a major difference, because arrays and structs are distinct. Arrays can only have numerical indexes; array["key"] is invalid. Conversely, structs can not use []. To access any properties of structs or classes, you use struct.propertyname (or -> if using a pointer); struct["propertyname"] is invalid.
classstats is an array of structs, so you index into the array using [] and then access the properties of the struct at that index using .
Another way to think about how to access what you want is evaluate things piece by piece. Things inside a [] will get evaluated first and then the result will be used as the index.
- classstats[ classnum ].propertyname = get the property "propertyname" of the struct at index classnum in the array classstats
- classstats[ classnum.propertyname ] = get the property "propertyname" of the struct/class classnum (not a struct/class; will generate a compile error), then use that property as the index to get the struct in the array classstats
- classstats[ classnum[propertyname] ] = get the variable at the index propertyname of the array classnum (not an array; will generate a compile error), then use that variable as the index to get the struct in the array classstats