Need help with Macros

Re: Need help with Macros

by SSJSketch » Tue Dec 29, 2015 12:42 am

Waterflame wrote:I have another question (AddOn related):
In the chat, if I writte:
Code: Select all
/run ChatFrame1:AddMessage(UnitLevel("player"))
or
Code: Select all
/script ChatFrame1:AddMessage(UnitLevel("player"))
it will writte the player's level in the chat, but, if I try
Code: Select all
ChatFrame1:AddMessage(UnitLevel("player"))
on the .lua document for an AddOn, it always writtes 0.


It could mean that the addon is being triggered before the player information is even created.

You could try adding a event trigger I.E. PLAYER_ENTERING_WORLD
Code: Select all
local f = CreateFrame("frame");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:SetScript("OnEvent", function()
  if event == "PLAYER_ENTERING_WORLD" then
    DEFAULT_CHAT_FRAME:AddMessage(UnitLevel("player"));
  end
end);
modui_ified
-----------------------------------------------------------------
"Success is buried in a garden of failure."
User avatar
SSJSketch
Grunt
Grunt
 

Re: Need help with Macros

by Dreez » Wed Dec 30, 2015 10:25 am

SSJSketch wrote:It could mean that the addon is being triggered before the player information is even created.

You could try adding a event trigger I.E. PLAYER_ENTERING_WORLD
Code: Select all
local f = CreateFrame("frame");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:SetScript("OnEvent", function()
  if event == "PLAYER_ENTERING_WORLD" then
    DEFAULT_CHAT_FRAME:AddMessage(UnitLevel("player"));
  end
end);

I don't think you can add messages to the chat on PLAYER_ENTERING_WORLD, I'd recommend testing it with PLAYER_TARGET_CHANGED as this is easier to reproduce
Dreez - PvP server
<Endzeit>
User avatar
Dreez
Knight-Lieutenant
Knight-Lieutenant
 

Re: Need help with Macros

by SSJSketch » Wed Dec 30, 2015 2:40 pm

Dreez wrote:
SSJSketch wrote:It could mean that the addon is being triggered before the player information is even created.

You could try adding a event trigger I.E. PLAYER_ENTERING_WORLD
Code: Select all
local f = CreateFrame("frame");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:SetScript("OnEvent", function()
  if event == "PLAYER_ENTERING_WORLD" then
    DEFAULT_CHAT_FRAME:AddMessage(UnitLevel("player"));
  end
end);

I don't think you can add messages to the chat on PLAYER_ENTERING_WORLD, I'd recommend testing it with PLAYER_TARGET_CHANGED as this is easier to reproduce

PLAYER_ENTERING_WORLD is when everything should be loaded (default ui at least). I even tested it to confirm and it still works.

As for PLAYER_TARGET_CHANGED, yes that would be easier to reproduce instead of reloading ui constantly but its dependent on the needs of the addon and how you want to test it.
modui_ified
-----------------------------------------------------------------
"Success is buried in a garden of failure."
User avatar
SSJSketch
Grunt
Grunt
 

Previous

Return to Addons & macros