CurseForge and Overwolf are joining forces!
Awesome More Information
  • 0

    posted a message on Edited: Creating an ACE author~
    The above is non-Aced. I'll walk through it.

    MM_Events = {
        Hunter = {},
        Warrior = {},
        Rogue = {}
    }


    This just creates a table with Hunter, Warrior, and Rogue sub-tables.

    Events.Hunter.UNIT_COMBAT = function()
    end
    
    Events.Warrior.UNIT_COMBAT = function()
    end
    
    Events.Rogue.UNIT_COMBAT = function()
    end


    These are just table elements that create functions where you can place the class-specific code to handle the UNIT_COMBAT event.

    function MM_OnEvent()
        if( MM_Events[playerClass] ) then MM_Events[playerClass][event]() end
    end


    This is called from your xml just like it is now, but instead of needing the if...else statements, it will directly call one of the functions in the Events table. You're giving up most of the if...else blocks in there, but you're instead performing a couple table references. So you may or may not be improving performance, but the effect should be negligible in either case.

    To explain further, if playerClass is "Hunter" and event is "UNIT_COMBAT" then the above code is the same as doing this:

    if( MM_Events.Hunter ) then MM_Events.Hunter.UNIT_COMBAT() end


    If you were registering multiple events, then you'd have to rework this a bit. I wrote it assuming you're only capturing UNIT_COMBAT.

    I also noticed a typo in this block. I should have been calling MM_Events[playerClass][event] not MM_Events[event]().

    Now that I look at your code more closely, I see that your addon doesn't run if it's not a warrior, hunter, or rogue, and most of the class code is the same, so here's a different suggestion:

    local playerClass, englishClass = UnitClass("player")
    local dodgeSpam
    local parrySpam
    local dodgeWav = "interface\\addons\\mongoosemania\\waves\\dodge.wav"
    local parryWav = "interface\\addons\\mongoosemania\\waves\\parry.wav"
    
    function MM_OnLoad()
       if ( playerClass == "Hunter" ) then
          dodgeSpam = "Mongoose Bite!"
          parrySpam = "Counter Attack!"
          this:RegisterEvent("UNIT_COMBAT")
       elseif ( playerClass == "Rogue" ) then
          parrySpam = "Disarm!"
          this:RegisterEvent("UNIT_COMBAT")
       elseif ( playerClass == "Warrior") then
          dodgeSpam = "Overpower!"
          this:RegisterEvent("UNIT_COMBAT")
       end
    end
    
    function MM_OnEvent(event)
       if ( event ~= UNIT_COMBAT ) then return end
    
       if (( arg1=="player" ) and ( arg2=="DODGE" )) then
             PlaySoundFile(dodgeWav)
             MMSplashFrame:AddMessage(dodgeSpam, 1, 1, 0, 1, 2)
       elseif (( arg1=="player" ) and ( arg2=="PARRY" )) then
             PlaySoundFile(parryWav)
             MMSplashFrame:AddMessage(parrySpam, 1, 1, 0, 1, 2)
       end
    end


    You really don't even need the if statement to check for UNIT_COMBAT, since that's the only event you're registering. If you register additional events, then I'd still recommend the event system I first posted, although all you'd need is the following, since your event no longer needs to check the class since class-specific values are stored in dodgeSpam and parrySpam.

    MM_Events = {}
    
    Events.UNIT_COMBAT = function()
    end
    
    Events.SOME_OTHER_EVENT = function()
    end
    
    function MM_OnEvent()
        MM_Events[event]()
    end
    Posted in: General Chat
  • 0

    posted a message on Edited: Creating an ACE author~
    First I'd suggest you don't pass the args to your event handler. They're already defined as globals so you're just creating extra variables each call. MM_OnEvent() is all you need here.

    Also, and this may not help performance, but you can try. Even if you don't want to Ace this addon, you can benefit from the structure Danboo introduced long ago (that inspired my use of it in Ace):

    MM_Events = {
        Hunter = {},
        Warrior = {},
        Rogue = {}
    }
    
    Events.Hunter.UNIT_COMBAT = function()
    end
    
    Events.Warrior.UNIT_COMBAT = function()
    end
    
    Events.Rogue.UNIT_COMBAT = function()
    end
    
    function MM_OnEvent()
        if( MM_Events[playerClass] ) then MM_Events[event]() end
    end


    This will eliminate the need for all the if ... else blocks. This probably won't affect memory, but could help with performance slightly. It's a lot more readable too. And you don't necessarily have to create the Hunter, Warrior, Rogue tables, but it eliminate the need to concatenate a new string if you did something like MM_Events[playerClass..event]() instead.
    Posted in: General Chat
  • 0

    posted a message on Happy... (read inside)
    Thanks, Moonwolf. Happy Solstice to you! :)
    Posted in: General Chat
  • 0

    posted a message on The Parrot, Pirate, and the Monkey
    Cardinal :)
    Posted in: General Chat
  • 0

    posted a message on The Parrot, Pirate, and the Monkey
    You may think I'm about to talk about swashbuckling and high seas adventures, but I'm not. If you already know I'm about to talk about Perl, Python, and Lua, then you're at least as big a geek as I am. :)

    I was browsing around for Lua information and learned that the Lua team is targetting a version, named Monkey, for release on the new Parrot VM. This is the first I've heard of it, but apparently Parrot is a new virtual machine that Perl 6 is being built for, but it's an independent project that will be able to run other languages. Pirate is Python's port and there's an implementation of the new Perl 6 standard called Pugs. So we have Pugs and Pirate ports of Perl and Python to Parrot. And someone brought a Monkey to the party. (I think I can hear Rowne chuckling.)

    I don't know any of the design team on these projects, but they all must have a warped sense of humor. Here are some links for those interested. I'm trying to figure out how to run Pugs. I'm a Perl fan, so I'm anxious to see what's new.

    Pugs
    Parrot
    Perl6
    Monkey
    Posted in: General Chat
  • 0

    posted a message on Vacation: December 26th - January 3rd
    Wow. That's qutie an itinerary. Have fun! I've been sailing once before in a small boat on Lake Michigan. What a humbling experience.
    Posted in: General Chat
  • 0

    posted a message on Categorized/Sorting OneBag
    This is freaking awesome looking, Ramble. I want a copy! :)
    Posted in: Addon Ideas
  • 0

    posted a message on Ya gotta laugh...
    That's great. I'd have a hard time picking a spec. :)
    Posted in: General Chat
  • 0

    posted a message on Out of town
    Just wanted to mention that I'll be out for the rest of the week. I'm going to stay with a sick friend to help him around the house. I'll have internet access but will be busy helping him and keeping up on school work, so I don't know how much time I'll have to watch the forums.
    Posted in: General Chat
  • 0

    posted a message on Firefox vs. Internet Explorer
    Thanks, Random. I've been using that for a little while now. Exactly what I needed.

    Btw, 47% of site users are on Firefox now, 40% on MS. Come on everyone. We need more converts!
    Posted in: General Chat
  • 0

    posted a message on AuctionIt?
    Happy to please, Akopian. I unfortunately don't know when or if I'll have time to work on my new version. I started one months ago but just haven't been able to keep on it or return to it. I'll certainly try to make sure all my current releases keep working, though.
    Posted in: Addon Ideas
  • 0

    posted a message on AuctionIt?
    Fixed now and uploaded to Curse: http://curse-gaming.com/mod.php?addid=453
    Posted in: Addon Ideas
  • 0

    posted a message on AuctionIt?
    I'll try to get AuctionIt fixed this week. All I'll be able to do is get it working. There won't be any new features. I don't know when if I'll ever get to work on a new AuctionIt.
    Posted in: Addon Ideas
  • 0

    posted a message on AH Wipe
    It's all related to the sudden non-existence of these elements all us addon coders have taken for granted for so long. You'll need to position the button manually with SetPoint when you Show it. Any of us who have ever written addons that add elements in relation to elements of the new Blizzard addons will have to be reworked to watch for when those addons load.
    Posted in: General AddOns
  • 0

    posted a message on Why are my addons broken?
    True.
    Posted in: General Chat
  • To post a comment, please or register a new account.