Thread Tools Display Modes
10-14-20, 02:40 PM   #1
KrS14
A Murloc Raider
Join Date: Oct 2020
Posts: 4
Stuck on TIME_PLAYED_MSG delay

Hi peeps,

I have the following in an addon I'm creating:

--Register /played event to unique frame
frame:RegisterEvent("TIME_PLAYED_MSG")
frame:SetScript("OnEvent", function(self, event, ...)
if (event == "TIME_PLAYED_MSG") then
TotalPlayed, PlayedThisLevel = ...
print("TotalPlayed, PlayedThisLevel "..TotalPlayed, PlayedThisLevel)
end
end)


-- Register Level up hook to unique frame
lvlup = CreateFrame("Frame", UIParent)
lvlup:RegisterEvent("PLAYER_LEVEL_UP")
lvlup:SetScript("OnEvent", function(self, event, ...)
if(event == "PLAYER_LEVEL_UP") then
print("Level up hook started")
newlevel = ...
print("NewLevel is: "..newlevel)
RequestTimePlayed()
inum = (#KLTcharstats+1)
print("inum and inslvl = "..inum)
newindex(inum)
if (inum == 1 and KLTcharstats[inum].clevel == 1) then
print("Running if, that is inum = 1 and clevel = 1 --- TotalPlayed = "..TotalPlayed)
KLTcharstats[inum].TTP = TotalPlayed
KLTcharstats[inum].TFL = TotalPlayed
end

After all this has run there are the correct results in my default chat for time played and level time played, from the event handler BUT i only ever get 1 in the if at the end. Do i have table init that runs before all this so no issues with the creation of the table or variables.

I've been banging my head against this for hours, what do I have wrong? Or is the time return just laggy as sin and I can't do what I need to?

Thanks for the input!!
  Reply With Quote
10-14-20, 05:14 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
There's always a delay between running RequestTimePlayed() and when TIME_PLAYED_MSG fires because it has to get this info from the server.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-14-20, 06:47 PM   #3
KrS14
A Murloc Raider
Join Date: Oct 2020
Posts: 4
Would using something like Ace be the only route to add a pause after levelup till i run functions?
  Reply With Quote
10-14-20, 07:48 PM   #4
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 308
Originally Posted by KrS14 View Post
Would using something like Ace be the only route to add a pause after levelup till i run functions?
https://wow.gamepedia.com/API_C_Timer.After
  Reply With Quote
10-14-20, 09:41 PM   #5
KrS14
A Murloc Raider
Join Date: Oct 2020
Posts: 4
I have read about this and tried it. Never got it to work, i'll give it another go tomorrow and report back.
  Reply With Quote
10-14-20, 11:35 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Here's what I would do.
Lua Code:
  1. local LevelTimes={};--  For this example, we'll say this is loaded from SavedVar
  2.  
  3. local EventFrame=CreateFrame("Frame");
  4. EventFrame:RegisterEvent("PLAYER_LEVEL_UP");
  5. EventFrame:RegisterEvent("TIME_PLAYED_MSG");
  6. EventFrame:SetScript("OnEvent",function(self,event,...)
  7.     if event=="PLAYER_LEVEL_UP" then
  8.         self.WaitingForPlayTime=true;-- Flag continuation
  9.         RequestTimePlayed();
  10.     elseif event=="TIME_PLAYED_MSG" and self.WaitingForPlayTime then
  11.         self.WaitingForPlayTime=false;--    Clear flag
  12.         LevelTimes[UnitLevel("player")-1]=...;--    Record time to complete level
  13.     end
  14. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-15-20, 11:44 AM   #7
KrS14
A Murloc Raider
Join Date: Oct 2020
Posts: 4
Originally Posted by SDPhantom View Post
Here's what I would do.
Lua Code:
  1. local LevelTimes={};--  For this example, we'll say this is loaded from SavedVar
  2.  
  3. local EventFrame=CreateFrame("Frame");
  4. EventFrame:RegisterEvent("PLAYER_LEVEL_UP");
  5. EventFrame:RegisterEvent("TIME_PLAYED_MSG");
  6. EventFrame:SetScript("OnEvent",function(self,event,...)
  7.     if event=="PLAYER_LEVEL_UP" then
  8.         self.WaitingForPlayTime=true;-- Flag continuation
  9.         RequestTimePlayed();
  10.     elseif event=="TIME_PLAYED_MSG" and self.WaitingForPlayTime then
  11.         self.WaitingForPlayTime=false;--    Clear flag
  12.         LevelTimes[UnitLevel("player")-1]=...;--    Record time to complete level
  13.     end
  14. end);
While not directly my solution SDPhantom, you completely made me realize I was going about the execution of everything in the wrong order.

I was sticking almost ALL my main work in PLAYER_LEVEL_UP, when it should have been in TIME_PLAYED_MSG that was my natural delay I needed

Thank you so much for your input, I'm about 4 days into learning LUA in any capacity lol so there's definitely some tricks to learn

All is working as intended now.

Last edited by KrS14 : 10-15-20 at 05:05 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stuck on TIME_PLAYED_MSG delay

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