1. This issue might sound silly as hell but I just can't seem to figure it out. My addon use alot of "self:Print" functions, but one of them don't seem to work .. It's the part where I register the event "GUILDROSTERUPDATE" and the callback is supposed to be a print:

    function rosterupdate()

    self:Print("Guild Roster Updated")
    

    end

    AceEvent:RegisterEvent("GUILDROSTERUPDATE", rosterupdate())

    So why the hell ain't this function working?

    Regards

    Hytra

    This issue might sound silly as hell but I just can't seem to figure it out. My addon use alot of "self:Print" functions, but one of them don't seem to work .. It's the part where I register the event "GUILDROSTERUPDATE" and the callback is supposed to be a print:

    function rosterupdate()

    self:Print("Guild Roster Updated")
    

    end

    AceEvent:RegisterEvent("GUILDROSTERUPDATE", rosterupdate())

    So why the hell ain't this function working?

    Because you're calling rosterupdate, not passing it. You want:

     AceEvent:RegisterEvent("GUILD_ROSTER_UPDATE", rosterupdate)
    

    Note the lack of () after rosterupdate.

    Thanks for the response. It still seems to get the same error, this is just weird as hell..

    What error.

    The LUA error 'Attempt to index global 'self' (a nil value)' and the line 24 matches the function I wrote above, so that's the one.

    It's impossible to tell without the code, but the error messages are always right. You're using 'self' in a context where that variable is not set.

    Is there any chance I can get your email and send the code there as I don't fancy code sharing on the web since there are these lovely thingies, called search engines :) Would be greatly appreciated.

    Umm.. I'm not sure why a search engine is a problem? Isn't this forum for us to learn, write, and fix code? I'd prefer to provide any help I can here, since there are other members of the forums that may be able to help you.

    The error is pretty simple, on the line it is complaining about, you are using self, which is not a local variable and is nil in the global environment. Don't do that =)

    Is there any chance I can get your email and send the code there as I don't fancy code sharing on the web since there are these lovely thingies, called search engines :) Would be greatly appreciated.

    Not cool dude. If your code is valuable enough to worry about it being crawled & indexed then you can pay someone to help you out.

    Otherwise post it here for everyone to see. It may be that jnwhiteh ends up answering most of the posts here, but sometimes others can answer & it's not nice to assume that he's always going to help out. Also, if you post here others can read and learn from the answers provided.

    If you're still worried about posting sensitive code then you should write a bit of test code that just contains your problem. This is a good exercise in any case and by doing so you may figure out your bug before you post it.

    I assume the Print function is defined as something like

    function MyAddon:Print(text)
        print(text)
    end
    

    and you can use that full name to call it, like this:

    local function rosterupdate()
        MyAddon:Print(text)
    end
    

    or if you want the self keyword to work you would need to be in a function defined like this:

    function MyAddon:rosterupdate()
        self:Print("Guild roster updated")
    end
    

    (replace all cases of MyAddon with whatever you're using to define your print function.)

    since "self" is merely hidden argument of functions defined with colon notation, to facilitate object oriented programming.

    Edit: When I think about Ace usage instead of just the self keyword, I realize you need to choose the second option, and your register event line should look like:

    MyAddon:RegisterEvent("GUILD_ROSTER_UPDATE", rosterupdate)
    

    Read the Ace documentation more thoroughly to understand why, and to get the rest of your code set up for this to work.

    Edit again: to elaborate on why I added "local" in the other way to fix the particular error you were experiencing: if the function is global, it is available to any other addon; if another addon had the same sloppy coding and had a global function with the same name, one would overwrite the other and break the addon that loaded first. The function declarations using the MyAddon variable don't need that because MyAddon is defined elsewhere so if it is local it would be declared local there, and if it isn't that's okay because it is presumably some unique addon-specific name (though IIRC local variables are more efficient.)

    I managed to get it to work!

    function rosterupdate()

    Semper_RD_Addon:Print("Guild Roster Updated")
    

    end

    thanks y'all