This article is a miscellaneous stub. You can help expand it by editing it

Porting addons to Classic

From Wowpedia
Revision as of 20:16, 17 June 2019 by Ketho (talk | contribs) (Created page with "{{UIHowTo}} {{Stub}} ==Changes== Addons for Retail (8.1.5) can mostly be easily ported to Classic (1.13.2) with minimal changes. For Vanilla (1.12) however, there is a bit mo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Changes

Addons for Retail (8.1.5) can mostly be easily ported to Classic (1.13.2) with minimal changes. For Vanilla (1.12) however, there is a bit more work involved.

  • Parameters like this, event and argN are no longer globals for the script handler. This was changed in Patch 4.0.1.
  • The this parameter was unique to WoW frame scripts. It can generally be replaced with self even though they are separate concepts. See self parameter for more information on self.
  • arg1, arg2, arg3, etc were replaced with the ... vararg. See the OnEvent frame script.

Quick fix

There are many different ways to create frames and handle frame scripts in XML. For simplicity's sake we will only describe a quick fix and a Lua only example.

  • XML
<Frame name="SomeAddon">
	<Scripts>
		<OnLoad>
			SomeAddon_OnLoad(self)
		</OnLoad>
		<OnEvent>
			SomeAddon_OnEvent(self, event, ...)
		</OnEvent>
	</Scripts>
</Frame>
  • Lua
function SomeAddon_OnLoad(frame)
	frame:RegisterEvent("ADDON_LOADED")
end

function SomeAddon_OnEvent(frame, event, addon)
	print(frame, event, addon)
end

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.

function f:OnEvent(event, addon)
	if event == "ADDON_LOADED" and addon == "SomeAddon" then
		self:UnregisterEvent("ADDON_LOADED")
	end
end

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", f.OnEvent)

self parameter

For more information about the self parameter, see WowAce: Coding Tips#Methods and Ref Manual: Function Definitions

The following are the same for passing an argument.

function Object:Bravo() end
function Object.Bravo(self) end

The following are the same for calling a function.

Object:Bravo()
Object.Bravo(Object)