Not a problem! As to how/why it works...
When using a.b=x form for a table, it works for simpler variables, but the key name 'b' can't have say, spaces, and can't be manipulated. I just used the longer form, a["b"]=x. Since in this form, 'b' is text, you can manipulate (in this case, concat with ..) or even use another variable name such as:
b="test"
a[b]=x
would translate to:
a["test"]=x
which is the same as:
a.test=x
As to nested tables, it's relatively simple. In a.b=x, a is the variable, which is a table. That's what a={} does. Then you make a new variable, the name of which (b) is called the 'key', and set the value. A nested table is setting the value to a table, like... a.b={}.
The longer for statement...
for _, v in pairs({'str', 'dex', 'int', 'wis', 'cha', 'con', 'lck'}) do
Several things happening here. A generic for statement is used like...
for k, v in pairs (t) do
-- do stuff
end
What it does is iterate over the key/values of the table t, with one iteration for each key. the {'str'...} in pairs() was just me putting a table directly into pairs, instead of a variable. You could also have done...
t={'str', 'dex', 'int', 'wis', 'cha', 'con', 'lck'}
for _, v in pairs(t) do
And have the same result!
Also, the form:
t={'str', 'dex', 'int', 'wis', 'cha', 'con', 'lck'}
is just a way to set the key/values when you make the table. It's the same as...
t={[1]='str', [2]='dex', [3]='int', [4]='wis', [5]='cha', [6]='con', [7]='lck'}
Which is the same as
t={}
t[1]='str'
t[2]='dex'
t[3]='int'
etc etc.
If you have any questions, feel free to ask.
|