Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
mNo edit summary
No edit summary
Tag: WoW API docs
(39 intermediate revisions by 12 users not shown)
Line 1: Line 1:
  +
{{wowapi}}
<center>'''LoadAddOn'''</center>
 
  +
Loads a LoadOnDemand addon.
 
loaded, reason = LoadAddOn(addonInfo)
   
 
==Arguments==
Request the loading of an On-Demand AddOn.
 
 
;addonInfo : <span class="apitype">number</span>|<span class="apitype">string</span> - The index or name of the AddOn in the user's AddOn list; Note that you cannot access Blizzard AddOns when using an index.
   
 
==Returns==
loaded, reason = LoadAddOn(index or "name")
 
  +
;loaded : <span class="apitype">boolean</span> - If the AddOn was loaded.
== Parameters ==
 
  +
;reason : <span title="nilable"><span class="apitype">string</span>?</span> - Locale-independent reason why the AddOn could not be loaded e.g. <code>"DISABLED"</code>, otherwise returns <code>nil</code> if the addon was loaded.
=== Arguments ===
 
:(index or "name")
 
   
  +
==Details==
:;index : Integer - The index of the AddOn in the user's AddOn list. Note that you cannot access Blizzard-provided AddOns through this mechanism.
 
  +
* Requires the addon to have the [[TOC_format#LoadOnDemand|LoadOnDemand]] TOC field specified.
:;name : String - The name of the AddOn to be queries. You can access Blizzard-provided AddOns through this mechanism.
 
  +
## LoadOnDemand: 1
=== Returns ===
 
  +
* LoadOnDemand addons are useful for reducing loading screen times by loading only when necessary, like with the different DeadlyBossMods addons/submodules.
:loaded, reason
 
   
 
===Reasons===
:;loaded : Flag - Indicates if the AddOn was loaded, 1 if it is, nil if it is not.
 
  +
These have corresponding globalstrings when prefixed with <code>"ADDON_"</code><ref>https://www.townlong-yak.com/framexml/9.1.0/GlobalStrings.lua#538</ref>
:;reason : String - The reason why the AddOn cannot be loaded. This is nil if the addon was loaded, otherwise it contains a code indicating the reason. (Observed reason codes: "DISABLED", "NOT_DEMAND_LOADED", "MISSING", "CORRUPT", "INTERFACE_VERSION", "DEP_MISSING", "DEP_INTERFACE_VERSION" and I asume other DEP_ reasons)
 
  +
<syntaxhighlight lang="lua">
  +
ADDON_BANNED = "Banned" -- Addon is banned by the client
  +
ADDON_CORRUPT = "Corrupt" -- The addon's file(s) are corrupt
  +
ADDON_DEMAND_LOADED = "Only loadable on demand"
  +
ADDON_DISABLED = "Disabled" -- Addon is disabled on the character select screen
  +
ADDON_INCOMPATIBLE = "Incompatible" -- The addon is not compatible with the current TOC version
  +
ADDON_INSECURE = "Insecure"
  +
ADDON_INTERFACE_VERSION = "Out of date"
  +
ADDON_MISSING = "Missing" -- The addon is physically not there
  +
ADDON_NOT_AVAILABLE = "Not Available"
  +
ADDON_UNKNOWN_ERROR = "Unknown load problem"
   
  +
ADDON_DEP_BANNED = "Dependency banned" -- Addon's dependency is banned by the client
=== Usage ===
 
  +
ADDON_DEP_CORRUPT = "Dependency corrupt" -- The addon's dependency cannot load because its file(s) are corrupt
local loaded,reason = LoadAddOn("MyOtherAddOn")
 
  +
ADDON_DEP_DEMAND_LOADED = "Dependency only loadable on demand"
if (not loaded) then
 
  +
ADDON_DEP_DISABLED = "Dependency disabled" -- The addon cannot load without its dependency enabled
if (reason == "DISABLED") then
 
  +
ADDON_DEP_INCOMPATIBLE = "Dependency incompatible" -- The addon cannot load if its dependency cannot load
do stuff
 
  +
ADDON_DEP_INSECURE = "Dependency insecure"
elseif (reason == "MISSING") then
 
  +
ADDON_DEP_INTERFACE_VERSION = "Dependency out of date"
do other stuff
 
  +
ADDON_DEP_MISSING = "Dependency missing" -- The addon's dependency is physically not there
elseif (reason == "CORRUPT") then
 
  +
</syntaxhighlight>
do something else
 
elseif (reason == "INTERFACE_VERSION") then
 
do something different
 
end
 
else
 
do something special
 
end
 
   
== Details ==
+
===Example===
  +
* Attempts to load a LoadOnDemand addon. If the addon is disabled, it will try to enable it first.
: Prior to the 1.8 patch, this could be used to load addons which were not on-demand if they were disabled at start up and then enabled during the play session. The 1.8 patch will restrict this to ONLY addons which are truly marked on demand in their .toc files (## LoadOnDemand: 1).
 
  +
<syntaxhighlight lang="lua">
  +
local function TryLoadAddOn(name)
 
local loaded, reason = LoadAddOn(name)
 
if not loaded then
 
if reason == "DISABLED" then
  +
EnableAddOn(name, true) -- enable for all characters on the realm
  +
LoadAddOn(name)
 
else
  +
local failed_msg = format("%s - %s", reason, _G["ADDON_"..reason])
  +
error(ADDON_LOAD_FAILED:format(name, failed_msg))
 
end
 
end
  +
end
   
  +
TryLoadAddOn("SomeAddOn")
----
 
  +
-- Couldn't load SomeAddOn: MISSING - Missing
__NOTOC__
 
  +
</syntaxhighlight>
{{Template:WoW API}}
 
  +
  +
* Manually loads and shows the Blizzard Achievement UI addon.
  +
/run LoadAddOn("Blizzard_AchievementUI"); AchievementFrame_ToggleAchievementFrame();
  +
  +
==Patch changes==
 
* {{Patch 1.8.0|note=Prior to the 1.8 patch, this could be used to load addons which were not on-demand if they were disabled at start up and then enabled during the play session. The 1.8 patch restricted this to ONLY addons which are truly marked on demand in their .toc files with <code>## LoadOnDemand: 1</code>}}
  +
  +
==See also==
  +
* {{api|IsAddOnLoaded}}()
  +
* {{api|UIParentLoadAddOn}}()
  +
  +
==References==
  +
{{Reflist}}
  +
  +
  +
{{#invoke:API_info/navbox|main|AddOn}}
  +
<!-- emmylua
  +
---@param addonInfo number|string index or name
  +
---@return boolean loaded
  +
---@return string? reason
  +
function LoadAddOn(addonInfo) end
 
-->

Revision as of 21:29, 21 November 2021

Loads a LoadOnDemand addon.

loaded, reason = LoadAddOn(addonInfo)

Arguments

addonInfo
number|string - The index or name of the AddOn in the user's AddOn list; Note that you cannot access Blizzard AddOns when using an index.

Returns

loaded
boolean - If the AddOn was loaded.
reason
string? - Locale-independent reason why the AddOn could not be loaded e.g. "DISABLED", otherwise returns nil if the addon was loaded.

Details

  • Requires the addon to have the LoadOnDemand TOC field specified.
## LoadOnDemand: 1
  • LoadOnDemand addons are useful for reducing loading screen times by loading only when necessary, like with the different DeadlyBossMods addons/submodules.

Reasons

These have corresponding globalstrings when prefixed with "ADDON_"[1]

ADDON_BANNED = "Banned" -- Addon is banned by the client
ADDON_CORRUPT = "Corrupt" -- The addon's file(s) are corrupt
ADDON_DEMAND_LOADED = "Only loadable on demand"
ADDON_DISABLED = "Disabled" -- Addon is disabled on the character select screen
ADDON_INCOMPATIBLE = "Incompatible" -- The addon is not compatible with the current TOC version
ADDON_INSECURE = "Insecure"
ADDON_INTERFACE_VERSION = "Out of date"
ADDON_MISSING = "Missing" -- The addon is physically not there
ADDON_NOT_AVAILABLE = "Not Available"
ADDON_UNKNOWN_ERROR = "Unknown load problem"

ADDON_DEP_BANNED = "Dependency banned" -- Addon's dependency is banned by the client
ADDON_DEP_CORRUPT = "Dependency corrupt" -- The addon's dependency cannot load because its file(s) are corrupt
ADDON_DEP_DEMAND_LOADED = "Dependency only loadable on demand"
ADDON_DEP_DISABLED = "Dependency disabled" -- The addon cannot load without its dependency enabled
ADDON_DEP_INCOMPATIBLE = "Dependency incompatible" -- The addon cannot load if its dependency cannot load
ADDON_DEP_INSECURE = "Dependency insecure"
ADDON_DEP_INTERFACE_VERSION = "Dependency out of date"
ADDON_DEP_MISSING = "Dependency missing" -- The addon's dependency is physically not there

Example

  • Attempts to load a LoadOnDemand addon. If the addon is disabled, it will try to enable it first.
local function TryLoadAddOn(name)
	local loaded, reason = LoadAddOn(name)
	if not loaded then
		if reason == "DISABLED" then
			EnableAddOn(name, true) -- enable for all characters on the realm
			LoadAddOn(name)
		else
			local failed_msg = format("%s - %s", reason, _G["ADDON_"..reason])
			error(ADDON_LOAD_FAILED:format(name, failed_msg))
		end
	end
end

TryLoadAddOn("SomeAddOn")
-- Couldn't load SomeAddOn: MISSING - Missing
  • Manually loads and shows the Blizzard Achievement UI addon.
/run LoadAddOn("Blizzard_AchievementUI"); AchievementFrame_ToggleAchievementFrame();

Patch changes

  • WoW Icon update Patch 1.8.0 (2005-10-10): Prior to the 1.8 patch, this could be used to load addons which were not on-demand if they were disabled at start up and then enabled during the play session. The 1.8 patch restricted this to ONLY addons which are truly marked on demand in their .toc files with ## LoadOnDemand: 1

See also

References