WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   C_Timer problem with weakaura trigger (https://www.wowinterface.com/forums/showthread.php?t=57694)

hurpy_derp 11-21-19 05:29 PM

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)


myrroddin 11-21-19 05:43 PM

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

hurpy_derp 11-21-19 05:47 PM

Quote:

Originally Posted by myrroddin (Post 334630)
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

myrroddin 11-21-19 06:00 PM

For a WeakAura, I am not sure either. Hopefully someone else pipes in.

Kanegasi 11-21-19 06:35 PM

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.

hurpy_derp 11-22-19 05:41 AM

Quote:

Originally Posted by Kanegasi (Post 334633)
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

jeruku 11-22-19 10:27 AM

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.

hurpy_derp 11-23-19 10:00 AM

Quote:

Originally Posted by jeruku (Post 334638)
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

jeruku 11-24-19 12:03 AM

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

Urtgard 11-24-19 08:30 AM

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.

hurpy_derp 11-24-19 06:08 PM

Quote:

Originally Posted by Urtgard (Post 334647)
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!


All times are GMT -6. The time now is 04:11 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI