• 0

    posted a message on Registering for a custom event?
    Resturecting an old thread because i have some questions about this and neither google nor wowace forums has been giving me answers today!


    From the manual
    AceEvent:SendMessage(message, ...)
    ...
    Parameters
    message - The message to send
    ...
    Any arguments to the message


    AceEvent:RegisterMessage(message[, callback [, arg]])
    Parameters
    ...
    arg
    An optional argument to pass to the callback function


    My code:
    [I]Filename: Macros.lua[/I]
    ..
    
    function MPS:SaveMacroProfile([B]name[/B])
    ..
    MPS:SendMessage("Profiles_Macros_loaded",[B]name[/B])

    Sending a message with a variable [name] from one addon..

    [I]Filename: Actionbars.lua[/I]
    ..
    function ABS:WOWLUA()
            print ("ABS: MPS loaded!!")
            print ([B]name[/B])
    end
    
    ABS:RegisterMessage("Profiles_Macros_loaded", "WOWLUA","[B]name[/B]")



    Getting the event in another addon, but not the variable name itself. Tried many approaches but ABS:WOWLUA() keeps saying name is nil! :(
    Hope I was clear enough else just ask.

    Thanks in advance for your support :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on SavedVariables + SavedVariablesPerCharacter
    Quote from Phanx
    Yeah, I recall having SV files for LootLink-type addons back in Vanilla/TBC that were 25-30 MB, and never had a problem with those.


    My comments comes from this guy (the author of http://wow.curse.com/downloads/wow-addons/details/market-watcher.aspx):

    Code-wise, nothing this addon does is unusual or violates any sort of conventions or expectations of authors, other than the amount of data it saves, which is completely within your control. At first I thought it was a ~32 meg table limit which Lua apparently has, but people are telling me they get data loss at far less than that. I can only tell you that at around ~10 megs, I myself have never lost data. If you are losing data, then save fewer scans.


    This has happened to me with this addon quite often and since that addon has had that bug from the start, I really thought there was a small limit.
    I did not think it could be the addon itself until now, so thanks for that.

    As far as my original question, after testing it out, it did indeed work just fine! Thank you for taking your time with me :)

    Cheers!
    Alex
    Posted in: Lua Code Discussion
  • 0

    posted a message on SavedVariables + SavedVariablesPerCharacter
    Quote from egingell
    The client handles the actual storage of the data. AceDB can't tell the difference between a global variable that is character specific and a global variable that is available to all characters. Global is global. So, using what you posted should work, but there's really only one way to find out for sure.


    As I understood it there is an unofficial 2mb limit per Saved File.
    I also need to have global options. I'll try this when I have some time and get back to you guys.

    Thanks.
    Posted in: Lua Code Discussion
  • 0

    posted a message on SavedVariables + SavedVariablesPerCharacter
    Quote from Farmbuyer
    Well, it can, but using per-char defeats the whole point of the profile design. You'd end up with profiles that can only be seen from the toon which created them.


    This is intended, especially since I save Macros/Keybinds and Action Bars for 10 characters.

    Global will contain options and small stuff :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on SavedVariables + SavedVariablesPerCharacter
    Hi,
    I am using AceDB today with great results.
    I am however wondering if the title if possible and if so, how I can specify which DB is per char and which DB is global.

    Would this be correct for example ?

    HaveWeMet\HaveWeMet.toc Edit
    ## Interface: 30000
    ## Title: Have We Met?
    ## SavedVariables: [B]HaveWeMetCount[/B]
    ## SavedVariablesPerCharacter: [B]HaveWeMetBool[/B]
    HaveWeMet.lua


    function HWM:OnInitialize()
       HWMGlobaldb = LibStub("AceDB-3.0"):New("[B]HaveWeMetCount[/B]",nil,"Default")
    
       HWMPerchardb = LibStub("AceDB-3.0"):New("[B]HaveWeMetBool[/B]",nil,"Default")
    end
    
    
    Posted in: Lua Code Discussion
  • 0

    posted a message on Wiki for functions and unit testing
    Quote from Xinhuan
    If wowwiki/wowpedia/wowprogramming all have no comments on it, then the only location you can find help about it is the Lua source code of Blizzard itself (FrameXML). You need to realize that the content on both wowwiki/wowpedia/wowprogramming are all edited by people like you and me, from whatever tests that we have done manually, or deduced by reading code.

    Blizzard does not provide support or help.


    This is strange given the number of WOWLUA developers out there and the nature of the addon itself (opensource, not allways so in license, but in form).

    It's a HUGE waste of knowledge, especially for new guys like me.

    If any of the mentioned siteowners are reading this, then this is my feedback to you, ALLOW COMMENTS ON EVENTS AND THE API, wowhead.com STYLE. Cheers :)

    Quote from Xinhuan

    So yes, all our addons, we DO manually test for quirks, unless by some fluke, someone else has done the same!


    Ok sounds quite weird,timeconsuming,inaccurate and not a good coder practice for a coder to go through all that code (speaking of the bigger addons..).

    Has anyone tested the WOWUnit test? Its an addon to WoW...



    You can use an IDE to write it (here's one), but to actually test for complete compatibility and functionality, you need to run it in-game. No emulator or compiler in the world is going to match the WoW client bit for shiny bit. Unless, the author took the time to mimic each and every function that Blizzard has including the ones not seen by looking in the FrameXML files, and, even then, I would still test in the game client itself.


    Like i said, WoWUnit is an addon in the actual game. Seems crude to me but i will sure give it a try as soon as i sort what bugs i found in my own addon.

    Also thank you for the tip of the IDE, using "Addon Studio for WoW" which has been abandoned for some time now, but it offered "Project" capabilities, unlike SciTE.
    Posted in: Need Help?
  • 0

    posted a message on Wiki for functions and unit testing
    Hello fellow authors :)

    Was using my addon for a long time until i realized that sometimes, it broke. After much pondering and testing I pinpointed the problem, UPDATE_BINDINGS. Searching through this forum I found an intersting post saying UPDATE_BINDINGS is fired everytime you get in combat..

    Which leads me to my first question, is there an actual WIKI (wowwiki and wowprogramming have no comments) with accurate info on how different events are behaving ? I am looking for wowhead comments to each of the events..

    My next question is how you guys do your testing. I cannot imagine someone with a project like AdiBags or Grid doing all that testing manually!

    I have searched and found WoWUnit but it doesn't seem to be maintained for a couple of months.

    Thank you for your patience with me this far,
    Cheers, Alex!

    PS. If you can point me to usefull snippets of LUA code I would be very gratefull as allways :):) DS.
    Posted in: Need Help?
  • 0

    posted a message on AceDB - Strange results
    Lombra
    Tack! :)

    Xinhuan
    Thank you for reminding me not to meddle with table.remove. It is not pop/shift as in perl, a big fail for my part.

    Also thank you for enlightening me about hashes and arrays, that is just confusing but something i have to live with. My original question has been answered ten times over and the more i read, the more i realized that I should not mess with LUA internals hehe :)

    Adirelle
    This was my original thought as well, indexing commands instead of array indexes. I have not tested your code fully but I have implemented it (along with the credits of course!).

    Thank you all for your patience with this! :D

    Alex
    Posted in: Lua Code Discussion
  • 0

    posted a message on AceDB - Strange results
    KLSdb:SetProfile("test9")
    KLSdb.profile["Reset"] = 0
    
    
    -- Go through the actionbars  and save them to file
    for actionID=1, GetNumBindings() do
       
       local command, key1, key2 = GetBinding(actionID);
       
       if key1 then
          KLSdb.profile[actionID] = {key1 = key1}
          if key2 then
             KLSdb.profile[actionID] = {key1 = key1,key2 = key2}
          end
       end
       
       
       
    end


    The above code produces the following db structure:
    ["test9"] = 
    {
         nil, -- [1]
         nil, -- [2]
        {
            ["key1"] = "W",
    	["key2"] = "UP",
        }, -- [3]
    
    ..
    ..
    ..
    }
    


    So in order to save space (and later in the code, not loading undefined vars!) i am forced to do this right after i have saved everything in the db:

    -- Remove non defined actions for the space and syntax sake
    for actionID2=1,#KLSdb.profile do
       if not KLSdb.profile[actionID2] then
          table.remove(KLSdb.profile,actiondID2)
       end
    
    end
    


    Producing the following db structure:
    ["test9"] = {
    [121] = {
    		["key1"] = "F",
    	    },
    [126] = {
                    ["key1"] = "C",
    	    },
    [127] = {
                    ["key1"] = "B",
    	    },
    ..
    ..
    ..
    }


    So my question to the ACEdb gurus here is basicly, why is the code in the first example creating a nil value even if I explicitly tell it not to do _anything_ unless key1 is defined ?

    Thanks in advance for your patience,
    Alex
    Posted in: Lua Code Discussion
  • 0

    posted a message on A clean ADDON_LOADED event?
    I'm confused. Why aren't you just listing Outfitter as a dependency in your .toc?


    I did not think of that, thank you for your tip :)

    Like Seerah said, list Outfitter as a dependency for your addon. If your addon has other modules that aren't dependent on Outfitter, list it as an optional dependency, otherwise list it as a required one. Then, just do this:


    Just some great pieces of code i was looking for, I thank you :)

    There's almost certainly a better way to accomplish your end goal here. Why do you want to know when all addons have been loaded?


    I will use your code to return if Outfitter isn't loaded.

    Also, the addon's name is arg1 not arg2. That is unless your event handler is calling KLS_Outfitter[event](self, event, addonName) which really doesn't make much sense.


    arg1 actually contained the event ADDON_LOADED when i went through my usual trial&error. Not sure why tho..

    Thank you all for your inputs, they are greatly appreciated! :)

    Alex
    Posted in: Need Help?
  • 0

    posted a message on A clean ADDON_LOADED event?
    KLS_Outfitter = KLS:NewModule("KLS: Outfitter", "AceConsole-3.0", "AceEvent-3.0")
    
    -- Wait for Outfitter to start
    function KLS_Outfitter:OnEnable()
    KLS:DebugMsg("KLS: Outfitter - OnEnable()")
    
        if (IsAddOnLoaded("Outfitter")) then
            KLS_Outfitter:Enable_On_ADDON_LOADED()
        else
            KLS_Outfitter:RegisterEvent("ADDON_LOADED")
        end
        
        KLS:DebugMsg("KLS: Outfitter - Enable() - Outfitter loaded")
    end
    
    function KLS_Outfitter:ADDON_LOADED(arg1,arg2)
        if arg2 == "Outfitter" then
        
            -- Outfitter addon loaded
            KLS_Outfitter:Enable_On_ADDON_LOADED()
            
            KLS_Outfitter:UnregisterEvent("ADDON_LOADED")
        end
    
    end
    
    function KLS_Outfitter:Enable_On_ADDON_LOADED()
        if (Outfitter) then -- Look for Outfitter global.
            KLS:DebugMsg("KLS: Outfitter - Enable() - Outfitter loaded")
            if not Outfitter:IsInitialized() then
                Outfitter:RegisterOutfitEvent('OUTFITTER_INIT', function () KLS_Outfitter:OnEnable() end)
            else
                DEFAULT_CHAT_FRAME:AddMessage("KLS: Outfitter ON")
                KLS:DebugMsg("KLS: Outfitter - OnEnable() - Registering events.")
                Outfitter:RegisterOutfitEvent('WEAR_OUTFIT', function (pOutfitt) KLS_Outfitter:OutfitterEvent("Wearing: ") end)
                Outfitter:RegisterOutfitEvent('DELETE_OUTFIT',function (_,pOutfitt) KLS_Outfitter:OutfitterEvent("Deleting: "..pOutfitt) end)
                Outfitter:RegisterOutfitEvent('ADD_OUTFIT',function (_,pOutfitt) KLS_Outfitter:OutfitterEvent("Adding: "..pOutfitt) end)
            end
        end
    end
    


    As you can see from the perfectly working but oh so ugly code above, when i enable my addon i register with ADDON_LOADED and THEN hook Outfitters events.

    Also, i cannot put KLS_Outfitter:Enable_On_ADDON_LOADED() in the ADDON_LOADED event as i want to be able to hook that event even when i run OnEnable.

    So my questions are:

    1. Is there a cleaner way of doing the above?

    2. Is it possible to tell when ALL ADDONS has been loaded ? My thoughts is looking for Blizzard* addons as they seem to load the last after some extensive testing. But is this the best way ?

    Thanks,
    Alex
    Posted in: Need Help?
  • 0

    posted a message on UnitClass("player") return nil at login
    Thank you Phanx, it works perfectly! +1 for you and credits in SVN! :)
    Posted in: Need Help?
  • 0

    posted a message on UnitClass("player") return nil at login
    Phanx, I am at work now but will try your suggestions when I get home tonight.
    With that said, i will try to respond to the best of my memorys ability ;)

    I solved UnitClass and the talent issue by calling the code from OnEnable and then left it at that. I have come to learn that WoWs events are still something new a a bit dodgy so i figured, i should'nt mess with the beast to much or I might get bitten.

    1. This is gold, i will make it local ASAP in case I wont run the code from 3.

    2. All i need to do is to save the talent spec, if this gives me that + localized name of the tree then it's a win+win.

    3. That code looks exciting and very clean. That will be my first task when I get home tonight.

    4. I am really just saving the name to a profile, so no worries there.
    The code is posted in Keyboard Layout Saver project so if you would like to read some more and comment, I would be thankfull :)

    One last mention, your reply is pure gold for a lua newbie and I would love to hear from you! :)

    Cheers,
    Alex
    Posted in: Need Help?
  • 0

    posted a message on Circular tables in lua ?
    Elsia, is your code more efficient than the above ?

    Until i find a good profiler addon I need to ask those type of questions ;)
    Posted in: Need Help?
  • 0

    posted a message on Circular tables in lua ?
    Adirelle my hero! Thanks ;)

    t = {}
    
    circular_list(t,"message 1",3)
    circular_list(t,"message 2",3)
    circular_list(t,"message 3",3)
    circular_list(t,"message 4",3)
    circular_list(t,"message 5",3)
    circular_list(t,"message 6",3)
    
    
    function circular_list(list_object,list_element,list_max)
       
       print("<---------Before!")
       for i, k in ipairs(list_object) do
          print("k-> "..k)
       end
       
       table.insert(list_object,list_element)
       
       i = 0
       
       if (#list_object > list_max)then
          
          print ("Buffer is now full - "..#list_object)
          
          while #list_object > list_max do 
             table.remove(list_object,1)
             print(#list_object.." is less than "..list_max)
          end
       end
       
       
       print ("after!------>")
       for i, k in ipairs(list_object) do
          print("k-> "..k)
       end
       print("\n\n")
       return list_object
       
    end
    



    I have a debug function that i want to default to 10 messages max until user turns debug on fully. If you would like to see the full code in action then please download my addon Keyboard Layout Saver.

    Cheers,
    Alex
    Posted in: Need Help?
  • To post a comment, please or register a new account.