Thread Tools Display Modes
12-03-16, 04:46 AM   #1
robertito54321
A Murloc Raider
Join Date: Aug 2012
Posts: 8
Code not executing when on login, only after reloadUI

So Im trying to load the player's portrait when a player logs in.
Unfortunately it doesnt load the portrait at login. It only loads it after I do a reloadUI.

I think this is caused because some data is not loaded yet. In a rare occasion it works and the portrait is loaded.
Im not sure how to solve this as I dont know what addon/event I need to check before I start loading the code.
Hopefully someone can help me out.

Test code:
Code:
local frame1 = CreateFrame("Frame", "PlayerPortrait", UIParent)
frame1:SetHeight(62)
frame1:SetWidth(62)
frame1:SetPoint("CENTER", UIParent, "CENTER", -328, -220)
frame1:SetFrameStrata("BACKGROUND")

local img1 = frame1:CreateTexture(nil, "BACKGROUND")
img1:SetHeight(62)
img1:SetWidth(62)
img1:SetPoint("TOPLEFT", 0, 0)

---------------

local w = CreateFrame("Frame")
w:RegisterEvent("PLAYER_ENTERING_WORLD")
w:RegisterEvent("ADDON_LOADED")
w:RegisterEvent("UPDATE_PENDING_MAIL")

function w:OnEvent(event, ...)
   if event == "PLAYER_ENTERING_WORLD" then --also checked with the other events
       SetPortraitTexture(img1, "player")
   end
end
  Reply With Quote
12-03-16, 05:45 AM   #2
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
try that instead?

http://wowprogramming.com/docs/api/IsLoggedIn

but there was some gimmick with those events and someone sure explain it soon
  Reply With Quote
12-03-16, 08:32 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
This will update the player portrait whenever it changes (logging in, new helm, haircut etc.)

Lua Code:
  1. local frame1 = CreateFrame("Frame", "RobertItoPlayerPortrait", UIParent)
  2. frame1:SetSize(62, 62)
  3. frame1:SetPoint("CENTER", UIParent, "CENTER", -328, -220)
  4. frame1:SetFrameStrata("BACKGROUND")
  5. frame1.img1 = frame1:CreateTexture(nil, "BACKGROUND")
  6. frame1.img1:SetAllPoints()
  7. frame1:SetScript("OnEvent", function(self, event, ...)
  8.            if event == "UNIT_PORTRAIT_UPDATE" then
  9.             SetPortraitTexture(frame1.img1, "player")          
  10.            end
  11.     end)
  12. frame1:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")

The [if event == "UNIT_PORTRAIT_UPDATE" then] and corrsponding [end] aren't needed if it's the only event registered.

Frame names are converted to global variables so PlayerPortrait is probably not a great one to use.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-03-16 at 08:41 AM.
  Reply With Quote
12-03-16, 08:47 AM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Should probably check that the unit ID is "player" when UNIT_PORTRAIT_UPDATE fires, so that it doesn't keep re-drawing the unit portrait unnecessarily.
__________________
  Reply With Quote
12-03-16, 11:48 AM   #5
robertito54321
A Murloc Raider
Join Date: Aug 2012
Posts: 8
Originally Posted by Fizzlemizz View Post
This will update the player portrait whenever it changes (logging in, new helm, haircut etc.)

...

Frame names are converted to global variables so PlayerPortrait is probably not a great one to use.
Thank you, this solved my problem
  Reply With Quote
12-03-16, 12:02 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Should probably check that the unit ID is "player" when UNIT_PORTRAIT_UPDATE fires, so that it doesn't keep re-drawing the unit portrait unnecessarily.
I noticed that and changed it to:
Code:
frame1:RegisterUnitEvent("UNIT_PORTRAIT_UPDATE", "player")
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Code not executing when on login, only after reloadUI

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off