WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   PLAYER_LEVEL_UP event (https://www.wowinterface.com/forums/showthread.php?t=58265)

glupikreten 10-11-20 03:09 AM

PLAYER_LEVEL_UP event
 
Hi,

Quick question

If i do something like this

Code:


print(UnitMaxXP("player"))
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LEVEL_UP")
f:SetScript(
        "OnEvent",
        function()
                print(UnitMaxXP("player"))
        end
)

Shouldn't i get different prints? Because for some reason i get the same... Like there is some delay or something in updating new player xp cap... if i put timer in that function with 1-2 seconds i get new value of max xp.

Is that like normal behaviour?

Xrystal 10-11-20 03:42 AM

It might have a delay similar to the player level function UnitLevel. But at least with that the PLAYER_LEVEL_CHANGED shows the old and new levels ... but ... you could try that event to see if it triggers after PLAYER_LEVEL_UP and may be enough for the new functions to have access to the new values.

glupikreten 10-11-20 08:07 AM

PLAYER_LEVEL_CHANGED works...

I found PLAYER_LEVEL_UP and just didnt think of searching for other event that fires when player levels up... (or levels can go down too?)

In any case thank you.

DahkCeles 10-11-20 10:14 AM

Although not applicable here since you found an event that works.... this is an alternative solution you could use when its necessary to defer an update:

Lua Code:
  1. local function doSomething()
  2.     -- do something
  3. end
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("SOME_EVENT")
  7. f:HookScript("OnEvent", function()
  8.     C_Timer.After(0, doSomething)  -- wait until the next frame to do something
  9. end)

glupikreten 10-11-20 10:48 AM

Oh never crossed my mind to try something after 0 seconds...

Ill remember that.

Thank you

Seerah 10-11-20 01:52 PM

Quote:

Originally Posted by glupikreten (Post 337082)
(or levels can go down too?)

They will when Shadowlands launches. ;)


All times are GMT -6. The time now is 08:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI