(→API: LatestInterface) Tag: WoW API docs |
|||
(42 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Stub/API}} |
||
{{UIHowTo}} |
{{UIHowTo}} |
||
− | Addons for Retail |
+ | Addons for Retail will in most cases work on Classic with removal of any non-Classic API. |
+ | If you don't have an error handling addon, get [https://www.curseforge.com/wow/addons/bugsack BugSack] or [https://auctioneeraddon.com/ Swatter] or enable CVar {{api|t=c|scriptErrors}}. |
||
− | For Vanilla (1.12) however, there is a bit more work involved. |
||
+ | |||
+ | See also [[Patch 1.13.2/API changes]]. |
||
+ | |||
+ | ==Globe== |
||
+ | [https://www.townlong-yak.com/globe/ Globe] can tell you which API functions/events in an addon have been removed in Classic, if the TOC is set to the Retail version and with <code>Globe: check-classic</code> |
||
+ | |||
+ | For example: https://www.townlong-yak.com/globe/#h:2a8385bff94e98a6bad8f5f09b45a148-reads |
||
+ | ## Interface: {{API LatestInterface}} |
||
+ | ## Globe: check-classic |
||
+ | |||
+ | ==API== |
||
+ | There is a list of [[World_of_Warcraft_API#Classic_Specific_Functions|Classic-specific]] API and a [[Global_functions/Classic|complete list]] of Classic API. The [[Getting_the_current_interface_number|TOC version]] is <code>{{API LatestInterface|classic}}</code> |
||
+ | |||
+ | You can use the [[WOW_PROJECT_ID]] global (defined in [https://github.com/Gethe/wow-ui-source/blob/4cb5ed50baa689244d16432fd5d36127c371795a/FrameXML/BNet.lua#L20-L22 BNet.lua]) to check for Classic or Retail. |
||
+ | local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) |
||
+ | |||
+ | * [[API Texture SetTexture|Texture:SetTexture]]() can no longer set color textures in [[Patch_7.0.3/API_changes|Patch 7.0.3]], use [[API Texture SetColorTexture|Texture:SetColorTexture]](r, g, b [, a]) instead. |
||
+ | * {{api|PlaySound}}() only accepts SoundKitIDs in [[Patch 7.0.3/API_changes|Patch 7.0.3]] |
||
+ | old: PlaySound("igMainMenuOptionCheckBoxOn") |
||
+ | new: PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON) |
||
+ | * {{api|PlaySoundFile}}() only accepts [[FileDataID]]s for game sounds in [[Patch 8.2.0/API_changes|Patch 8.2.0]] |
||
+ | old: PlaySoundFile("Sound/Spells/LevelUp.ogg") |
||
+ | new: PlaySoundFile(569593) |
||
==Maps== |
==Maps== |
||
Maps were reworked in [[Patch_8.0.1/API_changes|Patch 8.0.1]] and the stateful API was changed to be stateless. |
Maps were reworked in [[Patch_8.0.1/API_changes|Patch 8.0.1]] and the stateful API was changed to be stateless. |
||
+ | * [[WorldMapAreaID]]s were replaced with [[UiMapID]]s. |
||
− | * It's no longer needed to call {{api|SetMapToCurrentZone}}() and {{api|GetCurrentMapAreaID}}() to get the current zone UI map, instead use {{api|C_Map.GetBestMapForUnit}}() |
+ | * It's no longer needed to call {{api|SetMapToCurrentZone}}() and {{api|GetCurrentMapAreaID}}() to get the current zone UI map, instead use {{api|C_Map.GetBestMapForUnit}}("player") |
==Combat Log== |
==Combat Log== |
||
− | The combat log was reworked in [[Patch 2.4.0]] |
+ | The combat log was reworked in [[Patch_2.4.0/API_changes|Patch 2.4.0]] |
* The event payload is returned from {{api|CombatLogGetCurrentEventInfo}}() since Patch 8.0.1 |
* The event payload is returned from {{api|CombatLogGetCurrentEventInfo}}() since Patch 8.0.1 |
||
* See [[COMBAT_LOG_EVENT]] for details. |
* See [[COMBAT_LOG_EVENT]] for details. |
||
Line 17: | Line 40: | ||
==Frame Scripts== |
==Frame Scripts== |
||
Most Vanilla addons still define their frames in XML, since {{api|CreateFrame}}() was only added in [[1.10.0_API_changes_(Iriel)|Patch 1.10]] |
Most Vanilla addons still define their frames in XML, since {{api|CreateFrame}}() was only added in [[1.10.0_API_changes_(Iriel)|Patch 1.10]] |
||
− | * Parameters like <code>this |
+ | * Parameters like <code>this, event, arg1, arg2, arg3</code> are no longer globals for the script handler. This was changed in [[Patch_4.0.1/API_changes#Breaking_changes|Patch 4.0.1]]<br>They are now passed like so <code>[[UIHANDLER_OnEvent|OnEvent]](self, event, ...)</code> or <code>OnEvent(self, event, someVar1, someVar2, someVar3)</code> |
− | * The <code>this</code> parameter was unique to WoW frame scripts. It can generally be replaced with <code>self</code> |
+ | * The <code>this</code> parameter was unique to WoW frame scripts. It can generally be replaced with <code>self</code> |
− | * <code>arg1</code>, <code>arg2</code>, <code>arg3</code>, etc were replaced with the <code>...</code> vararg. See the [[Widget_handlers#Frame|OnEvent]](self, event, ...) frame script. |
||
===Quick fix=== |
===Quick fix=== |
||
− | There are multiple ways to |
+ | There are multiple ways to handle frame scripts in XML. For simplicity's sake we will only describe a quick fix in blue text. |
* Lua |
* Lua |
||
− | function SomeAddon_OnLoad(<font color="#4169E1"> |
+ | function SomeAddon_OnLoad(<font color="#4169E1">self</font>) |
− | + | <font color="#4169E1">self</font>:RegisterEvent("ADDON_LOADED") |
|
end |
end |
||
− | function SomeAddon_OnEvent(<font color="#4169E1"> |
+ | function SomeAddon_OnEvent(<font color="#4169E1">self, event, addon</font>) |
− | print( |
+ | print(self, event, addon) |
end |
end |
||
Line 47: | Line 69: | ||
===Lua only=== |
===Lua only=== |
||
It's also possible to create a frame and handle the scripts in Lua without use of XML, depending on how simple the addon is. |
It's also possible to create a frame and handle the scripts in Lua without use of XML, depending on how simple the addon is. |
||
− | function |
+ | local function OnEvent(self, event, addon) |
print(self, event, addon) |
print(self, event, addon) |
||
end |
end |
||
Line 53: | Line 75: | ||
local f = CreateFrame("Frame") |
local f = CreateFrame("Frame") |
||
f:RegisterEvent("ADDON_LOADED") |
f:RegisterEvent("ADDON_LOADED") |
||
− | f:SetScript("OnEvent", |
+ | f:SetScript("OnEvent", OnEvent) |
Revision as of 07:54, 31 March 2020
Addons for Retail will in most cases work on Classic with removal of any non-Classic API.
If you don't have an error handling addon, get BugSack or Swatter or enable CVar scriptErrors.
See also Patch 1.13.2/API changes.
Globe
Globe can tell you which API functions/events in an addon have been removed in Classic, if the TOC is set to the Retail version and with Globe: check-classic
For example: https://www.townlong-yak.com/globe/#h:2a8385bff94e98a6bad8f5f09b45a148-reads
## Interface: 100206 ## Globe: check-classic
API
There is a list of Classic-specific API and a complete list of Classic API. The TOC version is 11501
You can use the WOW_PROJECT_ID global (defined in BNet.lua) to check for Classic or Retail.
local isClassic = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
- Texture:SetTexture() can no longer set color textures in Patch 7.0.3, use Texture:SetColorTexture(r, g, b [, a]) instead.
- PlaySound() only accepts SoundKitIDs in Patch 7.0.3
old: PlaySound("igMainMenuOptionCheckBoxOn") new: PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
- PlaySoundFile() only accepts FileDataIDs for game sounds in Patch 8.2.0
old: PlaySoundFile("Sound/Spells/LevelUp.ogg") new: PlaySoundFile(569593)
Maps
Maps were reworked in Patch 8.0.1 and the stateful API was changed to be stateless.
- WorldMapAreaIDs were replaced with UiMapIDs.
- It's no longer needed to call SetMapToCurrentZone() and GetCurrentMapAreaID() to get the current zone UI map, instead use C_Map.GetBestMapForUnit("player")
Combat Log
The combat log was reworked in Patch 2.4.0
- The event payload is returned from CombatLogGetCurrentEventInfo() since Patch 8.0.1
- See COMBAT_LOG_EVENT for details.
Frame Scripts
Most Vanilla addons still define their frames in XML, since CreateFrame() was only added in Patch 1.10
- Parameters like
this, event, arg1, arg2, arg3
are no longer globals for the script handler. This was changed in Patch 4.0.1
They are now passed like soOnEvent(self, event, ...)
orOnEvent(self, event, someVar1, someVar2, someVar3)
- The
this
parameter was unique to WoW frame scripts. It can generally be replaced withself
Quick fix
There are multiple ways to handle frame scripts in XML. For simplicity's sake we will only describe a quick fix in blue text.
- Lua
function SomeAddon_OnLoad(self) self:RegisterEvent("ADDON_LOADED") end function SomeAddon_OnEvent(self, event, addon) print(self, event, addon) end
- XML
<Frame name="SomeAddon"> <Scripts> <OnLoad> SomeAddon_OnLoad(self) </OnLoad> <OnEvent> SomeAddon_OnEvent(self, event, ...) </OnEvent> </Scripts> </Frame>
Lua only
It's also possible to create a frame and handle the scripts in Lua without use of XML, depending on how simple the addon is.
local function OnEvent(self, event, addon) print(self, event, addon) end local f = CreateFrame("Frame") f:RegisterEvent("ADDON_LOADED") f:SetScript("OnEvent", OnEvent)