1. Hey guys!

    I'm somewhat new to addon creation, and I've encountered a little problem. I've reinstalled my windows and currently using default UI, but I've made myself a small unitframe, as the default playerframe is way to far from the actionbars, and as a fury warrior, I have to see my current rage almost every second.

    The problem with it, is that I used OnEvent script with UNIT_POWER, and its kinda laggy. The default playerframe shows my rage decrease as: 7 6 5 4 3 2 1 0.

    With the OnEvent script my frame shows it as: ..(zZz)..7..(zZz)..5..(zZz)..3..(zZz)..1 In some cases it even stucks on 1 (when I have 0), until my rage changes again.

    I was sure it's not about one more statusbar shown on screen, as it doesn't use as much resource to make it laggy. However, I tried this: I removed everything from the lua (well only made it a comment --[[ ), and what was remeaning is a frame, the OnEvent script, and the handler for it. The handler function printed my current rage to the chatframe, nothin else, and the result was the same: 7..5..3..1..

    I've solved the problem by switching to OnUpdate on the frame, but I think it will use too much resource when I will make the whole raidframes with power and health bars.

    The questions I'd like to be answered are: what causes the events to be laggy? How can it be solved? If I use OnUpdate, will it use much more CPU when there will be raidframes using OnUpdate too (instead of OnEvent)?

  2. I would use the OnUpdate with a flag to see if the "power" has changed or not

    i.e.

     local oldValue
    
     function bla(...)
       if (oldValue == newValue)
         return
    
       do something...
     end
    

    event lag issue:

    I dont know it for sure

    Maybe the UNIT_POWER Event ist thrown every x seconds and your power changes every x milliseconds.

  3. Hey guys!

    I'm somewhat new to addon creation, and I've encountered a little problem. I've reinstalled my windows and currently using default UI, but I've made myself a small unitframe, as the default playerframe is way to far from the actionbars, and as a fury warrior, I have to see my current rage almost every second.

    The problem with it, is that I used OnEvent script with UNIT_POWER, and its kinda laggy. The default playerframe shows my rage decrease as: 7 6 5 4 3 2 1 0.

    With the OnEvent script my frame shows it as: ..(zZz)..7..(zZz)..5..(zZz)..3..(zZz)..1 In some cases it even stucks on 1 (when I have 0), until my rage changes again.

    I was sure it's not about one more statusbar shown on screen, as it doesn't use as much resource to make it laggy. However, I tried this: I removed everything from the lua (well only made it a comment --[[ ), and what was remeaning is a frame, the OnEvent script, and the handler for it. The handler function printed my current rage to the chatframe, nothin else, and the result was the same: 7..5..3..1..

    I've solved the problem by switching to OnUpdate on the frame, but I think it will use too much resource when I will make the whole raidframes with power and health bars.

    The questions I'd like to be answered are: what causes the events to be laggy? How can it be solved?

    They aren't laggy. Event happen when they happen. The default unit frames use some manner of 'predictive' updates, which is how they are able to update progressively every frame to give you a new value. You can see this on a mana user much easier, it will constantly be updating. Compared to an event-based system, where the updates happen in 'blocks' even if the actual value seen by the client has changed.

    They're not laggy, that is just how they are sent.

    If I use OnUpdate, will it use much more CPU when there will be raidframes using OnUpdate too (instead of OnEvent)?

    An OnUpdate happens every single screen refresh for every single frame. An OnEvent happens when the events happen, for each frame registered for the event. Sometimes one will fire more often, sometimes another will, it depends entirely on your situation.

    Don't worry about 'CPU' usage, its a bogus measurement. Write the code to do what it needs to do, and if you need to make things more efficient later on, you can. You should try to avoid doing lots of work in an OnUpdate, since you can guarantee its going to be called very frequently.. but get something working properly first, then we can get down to brass tacks.

  4. Thanks for your responses. I'll leave it like this for now, and start working on my raid frames. Be prepared for another help request for secure templates. :)