Quantcast C_Timer problem with weakaura trigger - WoWInterface
Thread Tools Display Modes
11-21-19, 05:29 PM   #1
hurpy_derp
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2019
Posts: 5
C_Timer problem with weakaura trigger

So I'm trying to make a weakaura that triggers a couple seconds after a boss is killed, but for some reason it never works when it has a C_Timer on it, can someone help me out with it?

Code:
C_Timer.After(3, function(event,arg1, arg2, arg3, arg4, arg5, arg6, ...)
   if event == "BOSS_KILL" then
        return true
    end
end)
  Reply With Quote
11-21-19, 05:43 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,076
This might work.
Lua Code:
  1. local AddOnName, AddOn = ...
  2. local eventFrame = CreateFrame("Frame")
  3. eventFrame:SetScript("OnEvent", function(self, event, ...)
  4.     AddOn[event](self, ...)
  5. end)
  6. eventFrame:RegisterEvent("BOSS_KILL")
  7.  
  8. local function BossKill(event, ...)
  9.     return true
  10. end
  11.  
  12. function AddOn:BOSS_KILL(event, ...)
  13.     C_Timer.After(3, BossKill)
  14. end
  Reply With Quote
11-21-19, 05:47 PM   #3
hurpy_derp
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2019
Posts: 5
Originally Posted by myrroddin View Post
This might work.
Lua Code:
  1. local AddOnName, AddOn = ...
  2. local eventFrame = CreateFrame("Frame")
  3. eventFrame:SetScript("OnEvent", function(self, event, ...)
  4.     AddOn[event](self, ...)
  5. end)
  6. eventFrame:RegisterEvent("BOSS_KILL")
  7.  
  8. local function BossKill(event, ...)
  9.     return true
  10. end
  11.  
  12. function AddOn:BOSS_KILL(event, ...)
  13.     C_Timer.After(3, BossKill)
  14. end
Thanks, but I'm not really sure where I'm supposed to put this code
  Reply With Quote
11-21-19, 06:00 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,076
For a WeakAura, I am not sure either. Hopefully someone else pipes in.
  Reply With Quote
11-21-19, 06:35 PM   #5
Kanegasi
A Scalebane Royal Guard
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 415
A weakaura custom trigger requires a function object to work. You're getting an error because C_Timer.After is a function call in this scenario. Wrap what you have in a function object:

Lua Code:
  1. function(event)
  2.     C_Timer.After(3, function()
  3.         if event == "BOSS_KILL" then
  4.             return true
  5.         end
  6.     end
  7. end

If you're confused, basically weakaura trigger custom code has to start with the word "function" and end with "end", no exceptions, unless you have a global function to use, then you only use the function name and nothing else.
  Reply With Quote
11-22-19, 05:41 AM   #6
hurpy_derp
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2019
Posts: 5
Originally Posted by Kanegasi View Post
A weakaura custom trigger requires a function object to work. You're getting an error because C_Timer.After is a function call in this scenario. Wrap what you have in a function object:

Lua Code:
  1. function(event)
  2.     C_Timer.After(3, function()
  3.         if event == "BOSS_KILL" then
  4.             return true
  5.         end
  6.     end
  7. end

If you're confused, basically weakaura trigger custom code has to start with the word "function" and end with "end", no exceptions, unless you have a global function to use, then you only use the function name and nothing else.
Thanks for the input, but it's still not working. It's not giving any errors, just not triggering at all
  Reply With Quote
11-22-19, 10:27 AM   #7
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 201
Does WeakAuras still allow you to trigger the object 'On Finish' after setting a duration? And if so you won't need the timer and instead can use just the event check.
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
11-23-19, 10:00 AM   #8
hurpy_derp
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2019
Posts: 5
Originally Posted by jeruku View Post
Does WeakAuras still allow you to trigger the object 'On Finish' after setting a duration? And if so you won't need the timer and instead can use just the event check.
Can you elaborate? I can't find this option
  Reply With Quote
11-24-19, 12:03 AM   #9
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 201
Please excuse my limited knowledge since it's been a while since I played. If memory serves you could have a WeakAura show after a set amount of time, think it would be an invert toggle under the WA's display settings, then set the custom trigger to hide after a duration; though these might conflict with one another. Though in my attempt to relearn WA I came across a possible solution.

http://i.imgur.com/GZ6NpDC.png
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
11-24-19, 08:30 AM   #10
Urtgard
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 16
If you use Kanegasis example, the trigger function itself never returns true and your aura will never show up.

You could do this whit custom event.

Custom Trigger - Events: BOSS_KILL, CUSTOM_EVENT_NAME

Lua Code:
  1. function(event)
  2.     if event == "BOSS_KILL" then
  3.         C_Timer.After(3, function()
  4.                 WeakAuras.ScanEvents("CUSTOM_EVENT_NAME")
  5.                 -- If you want to pass some arguments
  6.                 -- WeakAuras.ScanEvents("CUSTOM_EVENT_NAME", argument1, argument2)
  7.         end)
  8.     end
  9.    
  10.     if event == "CUSTOM_EVENT_NAME" then
  11.         return true
  12.     end
  13. end

And maybe use a better name for your custom event and not this generic example.
  Reply With Quote
11-24-19, 06:08 PM   #11
hurpy_derp
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2019
Posts: 5
Originally Posted by Urtgard View Post
If you use Kanegasis example, the trigger function itself never returns true and your aura will never show up.

You could do this whit custom event.

Custom Trigger - Events: BOSS_KILL, CUSTOM_EVENT_NAME

Lua Code:
  1. function(event)
  2.     if event == "BOSS_KILL" then
  3.         C_Timer.After(3, function()
  4.                 WeakAuras.ScanEvents("CUSTOM_EVENT_NAME")
  5.                 -- If you want to pass some arguments
  6.                 -- WeakAuras.ScanEvents("CUSTOM_EVENT_NAME", argument1, argument2)
  7.         end)
  8.     end
  9.    
  10.     if event == "CUSTOM_EVENT_NAME" then
  11.         return true
  12.     end
  13. end

And maybe use a better name for your custom event and not this generic example.
Thank you!!! This worked perfectly!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » C_Timer problem with weakaura trigger

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