• 0

    posted a message on Circular tables in lua ?
    function circular_list(list_object,list_element,list_max)
        list = list_object
        i = 0
        while i < list_max do 
            table.remove[list,1]
        end
        
        table.insert(t,list_element)
    end


    Locks up the game so am guessing an infinite loop here..
    Posted in: Need Help?
  • 0

    posted a message on Circular tables in lua ?
    local KLSdebugbuffer = {}
    
    circular_list(KLSdebugbuffer,"Message here",3)
    
    function circular_list(list_object,list_element,list_max)
        list = KLSdebugbuffer
        current = list
        i = 0
        while i < list_max do
           current.value = i
           current.next = {}
           current = current.next
           i = i+1
        end
        current.value = list_element
        current.next = list
        KLSdebugbuffer = current
    end
    


    So i am trying to save memory and would like to use a circular list/table to handle my messages. The above is copied from lua manual but does not work as i thought it would.

    My question is, do you have a function that you have written already, for this purpose or can anyone spot the error and help me fix the above code ?

    Cheers,
    Alex
    Posted in: Need Help?
  • 0

    posted a message on UnitClass("player") return nil at login
    Moving UnitClass("player") to onEnable did indeed help. Thank you very much Sirow :)
    Posted in: Need Help?
  • 0

    posted a message on UnitClass("player") return nil at login
    Thanks will try this evening at home! :)
    Posted in: Need Help?
  • 0

    posted a message on UnitClass("player") return nil at login
    function KLS:GetCurrentClass()
        local class, classFileName = UnitClass("player");
        local talents = GetPrimaryTalentTree(0, 0);
    
       
       classes = {};
       
       classes["Druid"] = {
          [1] = "Balance", 
          [2] = "Feral Combat",
          [3] = "Restoration",
       };
       classes["Hunter"]= {
          [1] = "Beast Mastery",
          [2] = "Marksmanship", 
          [3] = "Survival"
       };
       classes["Mage"]=    {
          [1] = "Arcane", 
          [2] = "Fire", 
          [3] = "Frost"
       };
       classes["Paladin"]= {
          [1] = "Holy", 
          [2] = "Protection", 
          [3] = "Retribution"
       };
       classes["Priest"]= {
          [1] = "Discipline", 
          [2] = "Holy", 
          [3] = "Shadow"
       };
       classes["Rogue"]=   {
          [1] = "Assassination", 
          [2] = "Combat",
          [3] = "Subtlety"
       };
       classes["Shaman"]= {
          [1] = "Elemental", 
          [2] = "Enhancement", 
          [3] = "Restoration"
       };
       classes["Warlock"]= {
          [1] = "Affliction", 
          [2] = "Demonology", 
          [3] = "Destruction"
          
       };
       classes["Warrior"]= {
          [1] = "Arms", 
          [2] = "Fury", 
          [3] = "Protection"
       };
       classes["Death Knight"]= {
          [1] = "Blood", 
          [2] = "Frost", 
          [3] = "Unholy"
       };
       
       if (class ~= nil and talents ~= nil) then
        return (classes[class][talents])
       else
        print ("KLS class_function: Could not determine specialization of this character.");
        return ("Default")
       end
       
    end
    


    So I run this function in KLS:Initialize() like this

    local specialization = KLS:GetCurrentClass() or "Default";


    And it allways return nil, i tried
    local class, classFileName = UnitClass("player");

    in Initialize but it return nil also.

    Does this have anything to do with start events and variables not being fully loaded?
    How do you do it in your addons ?

    Cheers,
    Alex
    Posted in: Need Help?
  • 0

    posted a message on Event fire and addon table
    As promised, the code in Ace dialect:

    
    function KLS:OnInitialize()
       DEFAULT_CHAT_FRAME:AddMessage("Keyboard Layout Saver ON")
       
       local specialization = KLS:GetCurrentClass() or "Default"
       
       local defaults = 
       {
    	    profile =  
    	    {
    			actionID = { key1 = true, key2 = true},
                version = KLSversion
            },
       }
       
       
       
       KLSdb = LibStub("AceDB-3.0"):New("KeyboardLayoutSaver",defaults)
       
       KLS:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
       KLS:RegisterEvent("UPDATE_BINDINGS")
    end
    
    
    --User changed specs
    function KLS:ACTIVE_TALENT_GROUP_CHANGED(...)
    KLS:UnregisterEvent("UPDATE_BINDINGS")
       
       local specialization = KLS:GetCurrentClass() or "Default";
        
       -- Do we have keybinds for this spec ?
            if (KLS:ExistsProfile(specialization) == nil)then
                    print ("KLS Spec Change: No keybinds specified for spec "..specialization..". Saving keybinds...");
                    KLS:SaveProfil(specialization)
            else
                print ("KLS Spec Change: "..specialization..". loading keybinds...");
                KLS:LoadProfil(specialization)
            end
    KLS:RegisterEvent("UPDATE_BINDINGS")
    end
    


    Works flawless with my limited testing capability. Will beta test this with some guildies. If you see any error, do not hesitate to let me know :)

    Cheers,
    Alex
    Posted in: Need Help?
  • 0

    posted a message on Event fire and addon table
    That is what I did Adirelle, i will update this post when i get home with the new code. Using AceEvent has the added bonus of being beautifully written :D

    Thank you all for your help, you have all been very kind :)
    Posted in: Need Help?
  • 0

    posted a message on Event fire and addon table
    I went with AceDB solving the issue, completing code will come when i get home. Thank you for your help :)
    Posted in: Need Help?
  • 0

    posted a message on Event fire and addon table
    Ok thanks for your input, will make the db local for the whole addon. Strange this is I found the exact same setup in other addons also, but I havent found any addon reading the DB from events.

    What can I do about below ?
    Edit: Also, ACTIVE_TALENT_GROUP_CHANGED probably fires before your addon's variables load.
    Posted in: Need Help?
  • 0

    posted a message on Event fire and addon table
    local KLS = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0")
    
    function KLS:OnInitialize()
       DEFAULT_CHAT_FRAME:AddMessage("KeyboardLayoutSaver ON")
       
       local defaults = {
          sets = {}
       }
       
       KeyboardLayoutSaverDBPC=KeyboardLayoutSaverDBPC or {}
       
       --load defaults in
       for key, value in pairs(defaults) do
          if( KeyboardLayoutSaverDBPC[key] == nil ) then
             KeyboardLayoutSaverDBPC[key] = value
          end
       end
       
       self.db = KeyboardLayoutSaverDBPC  
    end
    
    --User changed specs
    local change_spec_frame = CreateFrame("FRAME", "KLS_Change_Spec");
    change_spec_frame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
    
    local function change_spec_event_handler(self, event)
       
       local specialization = class();
       
       -- Do we have keybinds for this spec ?
       if (specialization ~= nil) then   
            [B]if (self.db.sets[specialization]==nil)then[/B]
                    print ("KLS: No keybinds specified for spec "..specialization..". Saving keybinds...");
                    KLS:SaveProfil(specialization)
            else
                KLS:LoadProfil(specialization)
            end
       end
    end
    change_spec_frame:SetScript("OnEvent", change_spec_event_handler);


    The bold condition always fails, any ideas why?

    I recognize that self gets overwritten but how am I supposed to get self.db.sets in the event function ??

    I have tried:
    * Calling KLS.self.db thinking i need to define namespace (veteran perl coder here! :))
    * Reloading db as in the initialize function

    I will try:
    * Ignoring the self event altogether doing
    local function change_spec_event_handler(_, event)


    * Calling a second function that has access to self.db . But this seems hackish, hence me calling on expert help.

    Any and all help is appreciated, i have coded in perl a looooong time which means i do have past programming experience but this is my 4th day with LUA. I ordered a few books on the subject but it will take some time until they arrive.

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