WoW:Saving variables between game sessions (source)
Revision as of 04:48, 15 August 2023
, 15 August 2023Move page script moved page Saving variables between game sessions to WoW:Saving variables between game sessions without leaving a redirect
m (## is used in .toc file, not #) |
m (Move page script moved page Saving variables between game sessions to WoW:Saving variables between game sessions without leaving a redirect) |
||
| (6 intermediate revisions by 6 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{wow/uihowto}} | ||
An Addon may need to save settings and data between game sessions - that is, some information may need to persist through a user log out. To enable this, the addons may specify a number of variables to be saved to disk when the player's character logs out of the game, and restored when the character logs back in. Variables that are saved and restored by the client are called SavedVariables. | An Addon may need to save settings and data between game sessions - that is, some information may need to persist through a user log out. To enable this, the addons may specify a number of variables to be saved to disk when the player's character logs out of the game, and restored when the character logs back in. Variables that are saved and restored by the client are called SavedVariables. | ||
| Line 25: | Line 25: | ||
There are two pieces of information that need to persist between sessions: the number of characters the addon has met, and whether it has met any particular character. To save the count, a global variable, HaveWeMetCount is used (and saved on a per-account basis through #SavedVariables); while HaveWeMetBool is saved per-character and used to determine whether the addon has seen ''this'' character before. | There are two pieces of information that need to persist between sessions: the number of characters the addon has met, and whether it has met any particular character. To save the count, a global variable, HaveWeMetCount is used (and saved on a per-account basis through #SavedVariables); while HaveWeMetBool is saved per-character and used to determine whether the addon has seen ''this'' character before. | ||
<!-- This code in the middle of an article to illustrate a point; but it shouldn't fill everything. put it in a scrollable box --> | |||
This code in the middle of an article to illustrate a point; but it shouldn't fill everything. put it in a scrollable box --> | |||
=== HaveWeMet\HaveWeMet.toc === | === HaveWeMet\HaveWeMet.toc === | ||
<code> | |||
## Interface: 30000 | ## Interface: 30000 | ||
## Title: Have We Met? | ## Title: Have We Met? | ||
| Line 33: | Line 33: | ||
## SavedVariablesPerCharacter: HaveWeMetBool | ## SavedVariablesPerCharacter: HaveWeMetBool | ||
HaveWeMet.lua | HaveWeMet.lua | ||
</code> | |||
=== HaveWeMet\HaveWeMet.lua === | === HaveWeMet\HaveWeMet.lua === | ||
<code> | |||
local frame = CreateFrame("FRAME"); -- Need a frame to respond to events | local frame = CreateFrame("FRAME"); -- Need a frame to respond to events | ||
frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded | frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded | ||
| Line 59: | Line 61: | ||
print("HaveWeMet has met " .. HaveWeMetCount .. " characters."); | print("HaveWeMet has met " .. HaveWeMetCount .. " characters."); | ||
end | end | ||
</ | </code> | ||
== Common Pitfalls == | == Common Pitfalls == | ||
| Line 72: | Line 74: | ||
* <tt>WTF\Account\ACCOUNTNAME\SavedVariables.lua</tt> - Blizzard's saved variables. | * <tt>WTF\Account\ACCOUNTNAME\SavedVariables.lua</tt> - Blizzard's saved variables. | ||
* <tt>WTF\Account\ACCOUNTNAME\SavedVariables\AddOnName.lua</tt> - Per-account settings for each individual AddOn. | * <tt>WTF\Account\ACCOUNTNAME\SavedVariables\AddOnName.lua</tt> - Per-account settings for each individual AddOn. | ||
* <tt>WTF\Account\ACCOUNTNAME\RealmName\CharacterName\AddOnName.lua</tt> - Per-character settings for each individual AddOn. | * <tt>WTF\Account\ACCOUNTNAME\RealmName\CharacterName\SavedVariables\AddOnName.lua</tt> - Per-character settings for each individual AddOn. | ||
Deleting the WTF folder, or simply moving its contents will therefore reset the settings for all of your addons. | Deleting the WTF folder, or simply moving its contents will therefore reset the settings for all of your addons. | ||