I want to be able to dynamically create keys in a global saved variables table based on character name.
Code:
SomeAddon = {}
SomeAddon.Name = "SomeAddonName"
SomeAddon.GlobalTable = { }
...do stuff...
local function OnAddonLoaded(event, addonName)
if addonName ~= SomeAddon.Name then return end
EVENT_MANAGER:UnregisterForEvent("SomeAddon.Name", EVENT_ADD_ON_LOADED)
SomeAddon.AccountSavedVariables = ZO_SavedVars:NewAccountWide("SomeAddonName", 1, nil, SomeAddon.GlobalTable)
end
EVENT_MANAGER:RegisterForEvent(SomeAddon.Name, EVENT_ADD_ON_LOADED, OnAddonLoaded)
I want to check this table for a key which contains a value that == the current character name, and if not create it. The first value in each key would be the character name, followed by a set of values I pass based on functions.
So for example:
Code:
SomeAddon.GlobalTable[1] = {name= "character", var1 = "0", var2 = "0", var3 = "0"}
I also need to be able to determine the size of this global variable table so that if I have to add a new key for the current character (based on a check if they already exist in the table), I can make the new key tablesize+1.
The trouble I am having is the syntax. Whether it is using
for k,v in pairs(AccountSavedVariables.GlobalTable) and a variable + 1 to count the table size, or using the above format to add a key, I am getting "attempt to index a nil value" errors.