Help! Creating addon from macros

Dear All,

I’m trying to create an addon from these macros

/run TargetFrame:ClearAllPoints();
/run TargetFrame:SetPoint(“CENTER”, 290,190);
/run TargetFrame:SetUserPlaced(true);
/run FocusFrame:ClearAllPoints();
/run FocusFrame:SetPoint(“CENTER”,290,20);
/run FocusFrame:SetUserPlaced(true);
/run PartyMemberFrame1:ClearAllPoints();
/run PartyMemberFrame1:SetPoint(“CENTER”, -180,50);
/run PartyMemberFrame1:SetUserPlaced(true);
/run PlayerFrame:ClearAllPoints();
/run PlayerFrame:SetPoint(“CENTER”,-330,190);
/run PlayerFrame:SetUserPlaced(true);/run BuffFrame:SetScale(1.2);
/run BuffFrame:ClearAllPoints();
/run BuffFrame:SetPoint(“TOP”, 70,-10);
/run DebuffButton1:SetPoint(“TOP”,60,-55);
/run UIWidgetTopCenterContainerFrame:ClearAllPoints();
/run UIWidgetTopCenterContainerFrame:SetPoint(“TOP”, 400,-10);

The problem seems to be the line containing DebuffButton1;

Can someone suggest a solution, please?

Best Regards!

When converting a macro into an addon, there are two essential things to consider:

  1. An addon runs inside the lua environment, and thus shouldn’t have /run or /script commands. You can save remove all ‘/run’ from the code.
  2. Your addon will load before the UI is done loading, meaning some components may not be available yet. To circumvent this, hook up to the PLAYER_ENTERING_WORLD event which is triggered after everything has loaded, and run your addon code then.
local loadingFrame = CreateFrame("Frame");
loadingFrame:RegisterEvent("PLAYER_ENTERING_WORLD");
loadingFrame:SetScript("OnEvent",function()
	TargetFrame:ClearAllPoints();
	TargetFrame:SetPoint(“CENTER”, 290,190);
	TargetFrame:SetUserPlaced(true);
	FocusFrame:ClearAllPoints();
	FocusFrame:SetPoint(“CENTER”,290,20);
	FocusFrame:SetUserPlaced(true);
	PartyMemberFrame1:ClearAllPoints();
	PartyMemberFrame1:SetPoint(“CENTER”, -180,50);
	PartyMemberFrame1:SetUserPlaced(true);
	PlayerFrame:ClearAllPoints();
	PlayerFrame:SetPoint(“CENTER”,-330,190);
	PlayerFrame:SetUserPlaced(true); BuffFrame:SetScale(1.2);
	BuffFrame:ClearAllPoints();
	BuffFrame:SetPoint(“TOP”, 70,-10);
	DebuffButton1:SetPoint(“TOP”,60,-55);
	UIWidgetTopCenterContainerFrame:ClearAllPoints();
	UIWidgetTopCenterContainerFrame:SetPoint(“TOP”, 400,-10);
end);

Thanks a lot with the tips.
Now everything looks to work but the place of the debuffs.
Because there is no debuff active when I log in.

This is the Error that pops up:

Message: Interface\AddOns\ZandratarUI\code.lua:34: attempt to index global ‘DebuffButton1’ (a nil value)
Time: Sun Jan 13 18:13:44 2019
Count: 1
Stack: Interface\AddOns\ZandratarUI\code.lua:34: attempt to index global ‘DebuffButton1’ (a nil value)
Interface\AddOns\ZandratarUI\code.lua:34: in function <Interface\AddOns\ZandratarUI\code.lua:3>

Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = “TOP”
(*temporary) = -190
(*temporary) = -10
(*temporary) = “attempt to index global ‘DebuffButton1’ (a nil value)”

EDIT: Also after loading a screen (not the first time) the buffs go back to their default place.
EDIT: I changed the event to LOADING_SCREEN_DISABLED seems to be working for now. Only the error for the debuff is still poping up on first loading into the game.

P.S.: Anyone with suggestion how to remove this error?
Thanks in advance.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.