Navigation menu

WoW:Saving variables between game sessions: Difference between revisions

Jump to navigation Jump to search
m
Edited code style (fixed double scroll bars)
m (## is used in .toc file, not #)
m (Edited code style (fixed double scroll bars))
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.
<div style="max-height: 300px; margin: 0.5em; border: 0.2em solid black; overflow: auto; padding: 0.2em"><!--  
<!-- 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
</div>
</code>


== Common Pitfalls ==
== Common Pitfalls ==
Anonymous user