+ Reply to Thread
Results 1 to 10 of 10

Thread: Why is this not loading?

  1. #1
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default Why is this not loading?

    I am trying to test LibBossInfo before I make it public, and the test addon is not loading. For the life of me, I cannot figure out what is wrong. The library loads, but the test addon does not show up on my addon list. I have figured out it has something to do with either the Embed or Dependencies sections. The other thing I noticed is in Zorbas Buff Bars: in the Dependencies, are {"required", "before"} interchangable? {"before", "required"}?

    On a side note, is there a better way to handle errors in LibBossInfo than the way I have now? It works, but I'm not happy with it currently.

    LibBossInfo's RiftAddon.toc
    http://pastebin.com/F0ABFzr6

    LibBossInfo's LibBossInfo.lua
    http://pastebin.com/w3hdMtG8

    BossTest RiftAddon.toc
    http://pastebin.com/zgfX8Li6 -- mis-named pastebin. oh well

    BossTest BossTest.lua
    http://pastebin.com/4sdzQxuu

  2. #2
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    Follow-up post. When I comment out both the Embed and Dependencies in BossTest's RiftAddon.toc, I get the following error. Probably because LibBossInfo is not embedded, but wouldn't the global still be visible anyway?
    Code:
    Error: BossTest/BossTest.lua:1: attempt to index global 'Library' (a nil value)
        In BossTest / BossTest.lua
    stack traceback:
        BossTest/BossTest.lua:1: in main chunk

  3. #3
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    Probably a silly question, but are you actually embedding LibBossInfo inside BossTest? (ie. it's there as a subdirectory of BossTest). If it's not actually embedded inside, just lose the embed line, but leave the dependency in place.

    Reason I ask is, I can't see anything wrong with the tocs, which only really leaves the directory structure that I can think of.

    On the second point. assuming you're still loading LibBossInfo as a separate standalone addon, without the dependency, it could get loaded after BossTest, so the global wouldn't exist yet.
    Last edited by DoomSprout; 08-18-2012 at 06:15 AM.

    Gadgets: Unit Frames and Other Stuff for RIFT

  4. #4
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    Quote Originally Posted by DoomSprout View Post
    Probably a silly question, but are you actually embedding LibBossInfo inside BossTest? (ie. it's there as a subdirectory of BossTest). If it's not actually embedded inside, just lose the embed line, but leave the dependency in place.

    Reason I ask is, I can't see anything wrong with the tocs, which only really leaves the directory structure that I can think of.

    On the second point. assuming you're still loading LibBossInfo as a separate standalone addon, without the dependency, it could get loaded after BossTest, so the global wouldn't exist yet.
    Ah, no, I was loading the library as its own file. I will try putting it inside as a subdirectory.

  5. #5
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    And now I have an error in the library file. At least both load, even if the lib isn't being nice. This happened when I used the slash command in BossTest.
    Code:
    Error: LibBossInfo/LibBossInfo.lua:53: attempt to index local 'key' (a number value)
        In BossTest / This is only a test, event Slash.bosstest
    stack traceback:
        LibBossInfo/LibBossInfo.lua:53: in function 'GetLevel'
        BossTest/BossTest.lua:6: in function <BossTest/BossTest.lua:3>
    I had to modify BossTest's command registration. I'll have to learn why you can't have
    Code:
    local MyAddon = ...
    table.insert(Command.Slash.Register("bosstest"), {MyAddon:Test, "MyAddon", "desc"})
    
    function MyAddon:Test()
       -- do something
    end
    I changed it to local a local function.
    Code:
    local bossInfo = Library.LibBossInfo
    
    local function Test()
        local id = bossInfo:GetBossID("Rolf", "The Fall of Lantern Hook", "normal")
        local instance = bossInfo:GetInstance(id)
        local level = bossInfo:GetLevel(id)
        local bool = bossInfo:GetBoss(id)
        
        Print("Rolf's ID is " ..id)
        Print ("He is found in " ..instance)
        Print("This boss' level is " ..level)
        if bool then
            Print("What do you know, Rolf is a boss")
        end
        local detail = Inpect.Unit.Detail(id)
        local name = detail.name
        Print("Verifying Rolf's name is actually " ..name)
    end
    table.insert(Command.Slash.Register("bosstest"), {Test, "BossTest", "This is only a test"})

  6. #6
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    Errrr, I am dumb. I fixed it by changing "key" for "value". Anyway, I am still curious about that function registration in the slash commands. What's wrong with MyAddon:SomeFunc? Does it always have to be a local function?

  7. #7
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    Quote Originally Posted by Lorandii View Post
    Errrr, I am dumb. I fixed it by changing "key" for "value". Anyway, I am still curious about that function registration in the slash commands. What's wrong with MyAddon:SomeFunc? Does it always have to be a local function?
    I'm sure I'm going to explain this really badly, but I'll try anyway...

    Using a colon is purely shorthand in a function *call* for passing the table containing the function as the first parameter, which is how Lua fakes being object oriented.

    Calling...

    MyObject:Print("Hello")

    Is exactly the same as calling...

    MyObject.Print(MyObject, "Hello")

    And declaring a function...

    function MyObject:Print(message)

    Is the same as

    function MyObject.Print(self, message)

    In your event registration call, you're using the colon when just passing a reference to the function which isn't allowed, the colon can only be used when calling or declaring a function. If you change it to:

    table.insert(Command.Slash.Register("bosstest"), {MyAddon.Test, "MyAddon", "desc"})

    It'll probably work fine

    Note that in your example, the colon is actually unnecessary, and it would be better to declare the function as:

    function MyAddon.Test()
    -- do something
    end

    As the function isn't used as an object method.

    Sorry, this is a horrible explanation, but hopefully you can pick some sense out of it, or at least get some ideas of what to Google!

    - Wild

    Gadgets: Unit Frames and Other Stuff for RIFT

  8. #8
    Plane Walker Imhothar's Avatar
    Join Date
    Feb 2012
    Posts
    439

    Default

    The Embed table in the .toc has directories as keys (relative to the .toc), not addon identifiers. It only tells Rift that there is an embedded addon, not which one it is (that info is read from the embedded .toc). You have to physically put the entire library inside the parent addon, including it's .toc and everything. This is the exceprt from ImhoBags's .toc
    Code:
    --@no-lib-strip@
    Embed = {
    	["libs/LibString"] = true,
    	["libs/LibAsyncTextures"] = true,
    }
    --@end-no-lib-strip@
    Dependencies = {
    	LibString = { "required", "before" },
    	LibAsyncTextures = { "required", "before" },
    }
    Author of the Imhothar's Bags addon.

  9. #9
    Plane Walker Imhothar's Avatar
    Join Date
    Feb 2012
    Posts
    439

    Default

    Something to add to Wildlife's (not as terrible as he thinks) explanation:

    Even if the function is a member of the MyAddon table, you have to declare the function before adding it as slash command:

    Code:
    local MyAddon = ...
    table.insert(Command.Slash.Register("bosstest"), {MyAddon.Test, "MyAddon", "desc"})
    
    function MyAddon:Test()
       -- do something
    end
    The above does not work because at the point table.insert is called MyAddon.Test does not exist yet and is therefore nil. The same holds true if you use local functions. So it has to look like this:

    Code:
    local MyAddon = ...
    function MyAddon:Test()
       -- do something
    end
    
    table.insert(Command.Slash.Register("bosstest"), {MyAddon.Test, "MyAddon", "desc"})
    Last edited by Imhothar; 08-18-2012 at 10:46 AM.
    Author of the Imhothar's Bags addon.

  10. #10
    Champion Lorandii's Avatar
    Join Date
    Jun 2011
    Posts
    516

    Default

    Thank you for the pointer about how to manage the command (and event) function calls. I did know about the syntactic sugar, but since I never use that method, it completely slipped my mind. And Doom, your "bad explanation" is perfectly understandable, pending my failing brain. It is also totally accurate, again, as my brain dies.

    Here is the updated test code, now with more "where is the boss" returns. By the way, I am writing this library because I could not find any way to pull this data from the game. Yes, that means everything is hard coded and must be updated manually (Looking at you, Storm Legion). The question becomes: is this library necessary or useful to anyone?
    Code:
    local bossInfo = Library.LibBossInfo
    local BossTest = ...
    
    function BossTest.Test()
        local id = bossInfo:GetBossID("Rolf", "The Fall of Lantern Hook", "normal")
        local instance, subZone, difficulty = bossInfo:GetInstance(id)
        if not subZone then subZone = "N/A" end
        local level = bossInfo:GetLevel(id)
        local bool = bossInfo:GetBoss(id)
        
        Print("Rolf's ID is " ..id)
        Print ("He is found in " ..instance .. " in subzone " .. subZone .. " which has a difficulty of " .. difficulty)
        Print("This boss' level is " ..level)
        if bool then
            Print("What do you know, Rolf is a boss")
        end
        local detail = Inpect.Unit.Detail(id)
        local name = detail.name
        Print("Verifying Rolf's name is actually " ..name)
    end
    table.insert(Command.Slash.Register("bosstest"), {BossTest.Test, "BossTest", "This is only a test"})
    Going to test this again, right after lunch.
    Last edited by Lorandii; 08-18-2012 at 01:17 PM. Reason: flipping slash registration & function around

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts