View Single Post
07/09/20, 05:16 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
You should simply wait for the EVENT_ADD_ON_LOADED before doing anything. When that fires, you can be certain that the saved vars have been loaded.

Lua Code:
  1. -- Here MyAddOnSavedVar is nil and if you assign any value it will be overwritten later
  2.  
  3. EVENT_MANAGER:RegisterForEvent("MyAddOnEventNamespace",  EVENT_ADD_ON_LOADED, function(_, addOnName)
  4.     if addOnName == "MyAddOn" then
  5.         EVENT_MANAGER:UnregisterForEvent("MyAddOnEventNamespace", EVENT_ADD_ON_LOADED)
  6.         -- Here MyAddOnSavedVar is either nil if it didn't exist, or the previously stored value
  7.     end
  8. end)
  Reply With Quote