WoW:Saving variables between game sessions (source)
Revision as of 13:21, 13 April 2007
, 13 April 2007→Annoyances: This is the last time, I swear...
m (Removed duplicate ACCOUNTNAME folder reference in a file path.) |
m (→Annoyances: This is the last time, I swear...) |
||
| Line 92: | Line 92: | ||
savedVar = f() -- will fail to save g | savedVar = f() -- will fail to save g | ||
== Annoyances == | |||
If you save a table like this: | |||
tableName = { | |||
['key1'] = 'value1'; | |||
} | |||
and later alter the table to this: | |||
tableName = { | |||
['key1'] = 'value1'; | |||
['key2'] = 'value2'; | |||
} | |||
tableName['key2'] will not be available for use unless you delete the [[SavedVariables]] file or put in extra code like this: (edit: [[User:Egingell|Egingell]] 09:11, 13 April 2007 (EDT) | |||
tableName = {} | |||
local tableNameDefaults = { | |||
['key1'] = 'value1'; | |||
['key2'] = 'value2'; | |||
} | |||
function AddOnName_OnLoad() | |||
this:RegisterEvent('VARIABLES_LOADED') | |||
end | |||
function AddOnName_OnEvent(event) | |||
if event == 'VARIABLES_LOADED' then | |||
for k,v in pairs(tableNameDefaults) do | |||
if not tableName[k] then | |||
tableName[k] = v; | |||
end | |||
end | |||
end | |||
end | |||
It might also work, if you declare an empty table first, like this: | |||
tableName = {} | |||
tableName = { | |||
['key1'] = 'value1'; | |||
['key2'] = 'value2'; | |||
} | |||
[[User:Egingell|Egingell]] 09:04, 13 April 2007 (EDT) | |||
[[Category: HOWTOs|Save Variables Between Game Sessions]] | [[Category: HOWTOs|Save Variables Between Game Sessions]] | ||