Originally Posted by Phanx
That's because you're doing it wrong. Here's what your code is currently doing:
Code:
mounts = {}
category="new_category"
mount="Swift Moonsaber"
- The first line creates the table { } and assigns it to the variable "mounts".
- The second line creates the string "new_category" and assigns it to the variable "category".
- The third line creates the string "Swift Moonsaber" and assigns it to the variable "mount".
Now when you do:
Code:
mounts[category][mount]=true
This is what's happening:
- The code looks for a table under the variable name "mounts". This returns the table, {}.
- The code looks for the value under the variable name "category" as a table key. This returns nil, because the "mounts" table is empty.
- The code looks for the value under the table returned by "mounts[category]". This fails and throws an error, because "mounts[category]" is nil, not a table.
What you need to do is:
Code:
local mounts = {}
local category = "new_category"
local mount = "Swift Moonsaber"
mounts[category] = {}
Then you can add values to the category the way you were trying to:
Code:
mounts[category][mount] = true
|
Thanks Phanx,
I think I have finally understood :-)
On a side note, you should never create global variables with such generic names as "mounts" and "category" and "mount"...
|
Yes I know,
the above code was only a pseudo code I wrote to show the problem.
In the addon I surely use local for my names. :-)
Btw thanks for the great explanation on how the global var impact in the addon dataspace.
Now I an continue the rewrote :-)