• 0

    posted a message on Stupid question about scope of AceDB variables
    Quote from Adirelle
    Not loading the library, starting by LibStun, should result in lots of nil errors and/or library not found. I think this is apart from your error.

    BTW, using self.db.global.toons after setting a value in :update() like you did is useless (unless your real code doesn't do it). Moreover, you want to set up defaults, pass a table to AceDB:New. E.g. :

    local me = UnitName("player") -- this available at loading time
    local DEFAULT_SETTINGS = {
      global = {
        toons = {
          [me] = { x = 0 }
        }
      }
    }
    function MyAddon:OnInitialize()
        self.db = LibStub("AceDB-3.0"):New("MyAddonDB", DEFAULT_SETTINGS)
    end
    


    Thanks! I recall using that that method in the past now that you point it out.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    Quote from Allara
    Heh, he's probably not trying to hide it, just make it easier for us to parse quickly. Unfortunately, it backfired.


    Quote from Phanx
    It always backfires... and even if his motivation wasn't to hide the code, that is the end result of the extra time and effort he spent. :p


    Sorry Phanx, have to disagree with you, though I agree with the point you are making.

    I agree that posting code I've never even executed was rather pointless. I should have come up with a test case that exhibited my problem and tested it first.

    When I actually did that, I resolved the problem on my own.

    Though I appreciate that you would have done so, I'd have felt guilty giving you pages and pages of code to parse through to help me out with my problem.

    And again, I originally thought that it was a simple problem of my misunderstanding scope, which turns out to not be true, but I didn't know that at the time. In other words, I never expected anyone to actually debug my code for me. The code sample was just to highlight what I was doing in general to put a frame around the scope discussion.

    I think is is very cool that you guys are willing to help out like that though. :D
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    Quote from pigmonkey
    I remember when I made my first Ace addon, I named it "C[...]". It worked fine, but I later renamed it to "A[...]" and all of a sudden it broke because it was the first alphabetical addon and I wasn't including the Libraries. I'm guessing that your addon is "Badger", which means maybe the intermittent problem is because you are turning on and off another addon that precedes it that uses some of the libraries?

    Though, I'm also assuming this isn't a problem since LibStub throws errors when it can't find libraries, so I would assume you would see those too.


    That's what's confusing me too. Gonna try it out and see if it helps though.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    I'm working up a simple example to post that displays my problem (Hopefully I'll figure out what's wrong just by making the example work), and I noticed something.

    My xml doesn't include the db library. Could that be the reason it's working sporadically? Maybe a loading order problem?

    <Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
      <Script file="Libs\LibStub\LibStub.lua"/>
      <Include file="Libs\AceAddon-3.0\AceAddon-3.0.xml"/>
      <Include file="Libs\AceConsole-3.0\AceConsole-3.0.xml"/>
    </Ui>


    Well, I just realized I don't have any of the libraries in my addon directory either....
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    exactly. Sorry, trying to post simplified code has resulted in some garbage. I am NOT getting any syntax errors.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    Sure, I can do so when I get back home later. I just assumed it was something simple and basic I was misunderstanding on the scope of the db variables, so the code wouldn't really matter specifically.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    It's not working again. Very odd.

    If I /reloadui then next() will print the right value.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    I have swatter loaded, I'd know if there was an error.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    I'm wondering if I changed code and didn't exit the game completely and something wasn't completely loaded properly.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    That's strange. It seems to be working fine now and I swear I didn't change anything.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    Quote from Allara
    Are you properly setting the variable "me" in OnEnable before using it? You don't in the code above.


    Oops. Yes, in the real code I am.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Stupid question about scope of AceDB variables
    It's been a few years since I dabbled in lua / addons so I'm pretty rusty.

    When the code runs for the first time it sets the variable to 0 and that is saved in the SavedVariables perfectly. But when I run next() which runs update() first, I still get 0 even though the update function updated the variable to 5.

    If I log out the 5 is saved in the SavedVariables and when logging back in everything works as expected.

    But why doesn't next() see the expected value of 5 until a relog?

    MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceConsole-3.0", "AceEvent-3.0")
    
    function MyAddon:OnInitialize()
        self.db = LibStub("AceDB-3.0"):New("MyAddonDB")
    end
    
    function MyAddon:OnEnable()
        self:update()
    
        Badger:RegisterChatCommand("next", "next")
    
        if self.db.global.toons == nil then
           self.db.global.toons = {}
        if self.db.global.toons[me] == nil then
           self.db.global.toons[me] = {}
        if self.db.global.toons[me].x == nil then
           self.db.global.toons[me].x = 0
    
    end
    
    function MyAddon:next()
        self:update()
    
        for key, val in pairs(self.db.global.toons)
        do
             MyAddon:Print(self.db.global.toons[key].x)
        end 
    end
    
    function MyAddon:update()
    
        me = UnitName("player")
    
        self.db.global.toons[me].x = 5
    end
    
    
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.