• 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Farmbuyer
    LibStub is like a showcase for most of Lua's idioms all in one place.

    That's not a bad thing. Every language has its idioms -- its traditions and conventions and ways of doing things that you won't find in other languages. With Lua, a lot of those idioms are in the syntax, not the behavior. It would be 100% possible to write LibStub in a more "example in a textbook" format with exactly the same runtime behavior, but then it would be about 3 times as long. :-)

    Once you can understand this line in LibStub:NewLibrary,
    self.minors[major], self.libs[major] = minor, self.libs[major] or {}
    

    then you've got a big chunk of Lua's idioms under your belt right there.

    The textbook version of that line is like
    self.minors[major] = minor
    local temp = self.libs[major]
    if temp ~=  nil then
        self.libs[major] = temp    -- does nothing
    else
        self.libs[major] = {}
    end
    ignoring some details about nil/false conversions.




    So alright I'm gonna try and parse this and tell you where my hangups lie.

    self.minors[major] = minor


    Major is I presume a # because its within []. Self is the name of the object (so if I put pancakes in the () of a function I think Self returns pancakes, but I'm not sure).

    What I don't get here is what a minor is, are we talking revision?

    local temp = self.libs[major]


    So what this is doing is creating a local variable called "temp" which has the value of thenameofthisobjectorfunction.libs[revisionnumberhere]?

    This variable will only exist for as long as we are within the current object and having gone a level down or up.

    if temp ~=  nil then
        self.libs[major] = temp    -- does nothing
    else
        self.libs[major] = {}
    end


    If that variable actually leads somewhere then we reaffirm the variable (couldn't you just put end here)?

    Otherwise if it doesn't lead anywhere (ie. returns a nil value) it creates a table out of that. For what reason I'm not sure (just for example I assume).

    self.minors[major], self.libs[major] = minor, self.libs[major] or {}


    So then this line is doing the following. Creating a global variable, applying a temporary variable to that global, then either reaffirming it or creating a table out of it?

    I suppose what you are showing me here is how to make libraries? I'm actually not sure where to find this kind of information other than:

    https://github.com/tekkub/libdatabroker-1-1/wiki/API

    I'll try and edit that example I was given and see where I'm going right or wrong. Need to pack up and go home first though. LibData stuff reminds me of modding for Starbound. Lots of commas.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    To add to Lombra's suggestion to use LibDataBroker instead of the Titan Panel API, it should be mentioned that Titan Panel can display LibDataBroker plugins, so if you write your plugin using LibDataBroker, you can keep using Titan Panel and have your plugin show up on it. (The reverse is not true however; there are not any DataBroker display addons that will show Titan plugins.)

    Also, there's a minor issue in Lombra's example code; the tooltip (probably) won't appear correctly or at all unless you add self:Show() to the end of it, after you've added all the lines.

    If this is your first project, I cannot recommend strongly enough that you avoid using the Titan Panel API. You may be learning something about addon programming in general, but you're also learning a lot of dead-end "proprietary" APIs (eg. locked into Titan Panel, which frankly I'm amazed is still even in existence at this point... it must be on about author #25 by now) and probably bad coding habits from using such a badly designed API, not to mention whatever other (probably) badly written plugins you're looking at for examples. :(


    Well I don't want that avatar of yours looking any more shocked than it already does. I'll rebuild my addon in LibDataBroker and most certainly poke at you all whenever I get stuck.

    But I feel like the last week has been incredibly productive. I went from Lua looking like hieroglyphics to me to making a mod that 95% works. That's much better than the 5% I was predicting when I started!

    Thanks again to all of you for your help so far, its been way more helpful than you might think >.>.

    edit: Opened LibStub.lua and had a stroke. Will read up more.

    edit#2:

    -- - Constants --------
    local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
    local plugin = LibStub("LibDataBroker-1.1"):NewDataObject(TheIOSModProf1, {
    type = "data source",
    text = "Not AFK",
    icon = [[Interface\Icons\Spell_Nature_TimeStop]],
    label = "AFK Timer",
    OnClick = function(self, button)
    if button == "LeftButton" then
    SendChatMessage("", "AFK")
    elseif button == "RightButton" then
    EasyMenu(dropdown, addon, self, 0, 0, "MENU")
    end
    end,
    OnTooltipShow = function(self)
    self:AddLine("Broker: AFKTimer", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
    self:AddLine(" ")
    self:AddLine(db.note and "You are AFK: |cffffffff"..db.note or "You are not AFK.")
    self:AddLine(" ")
    self:AddLine("Left-click to toggle AFK status.", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
    end,
    self:Show()
    })


    So place self:Show() there?

    I can reverse engineer this thing to do what I want if this is how complicated getting it all to show in Titan Panel is :o.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Lombra
    The Titan Panel API is horrible, imo. I highly recommend that you have a look at LibDataBroker. It's essentially a different way of making plugins that's much easier, and will also work with a lot of Broker display addons. (panel addons, if you will)

    Here's an example of a simple "plugin":
    local plugin = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
        type = "data source",
        text = "Not AFK",
        icon = [[Interface\Icons\Spell_Nature_TimeStop]],
        label = "AFK Timer",
        OnClick = function(self, button)
            if button == "LeftButton" then
                SendChatMessage("", "AFK")
            elseif button == "RightButton" then
                EasyMenu(dropdown, addon, self, 0, 0, "MENU")
            end
        end,
        OnTooltipShow = function(self)
            self:AddLine("Broker: AFKTimer", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
            self:AddLine(" ")
            self:AddLine(db.note and "You are AFK: |cffffffff"..db.note or "You are not AFK.")
            self:AddLine(" ")
            self:AddLine("Left-click to toggle AFK status.", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
        end,
    })

    Whenever you want to change the text or icon, simply do:
    plugin.icon = "new\\icon"
    plugin.text = "new text too"

    I understand if you want to stick with what you already are familiar, of course! Also could've explained better, but I'm tired!


    I'll try learning these "lib" thingies next since folks have mentioned them elsewhere. I do agree that titan is kinda nasty. As a person coming fresh into the stuff their documentation and the way a lot of stuff works is terrible or counter intuitive respectively.

    I'm just pleased that my only hangup at this point is a lack of functionality rather than my own terrible coding (which I'm sure isn't helping but it works and I'm happy that my first project wasn't a bust).
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Ok I'm at my last hurdle I think.

    http://pastebin.com/0Sp3RNu6

    The addon updates everything on character login now but I'm perplexed.

    Titan Panel doesn't (appear) to have a function to update the icon image once its been added. Any ideas how I can redirect the onload function to the onevent function temporarily to "halt" it long enough to grab the icon image?

    Or if you've used titan panel perhaps you know of a function I'm missing. Strangely:

    TitanPanelPluginHandle_OnUpdate({TIOSP1.id, TITAN_PANEL_UPDATE_ALL})

    Doesn't actually update "all" it just updates tooltip, hover text, and button text >.>...that's 3/4 so not all.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Thanks for the explanation. Its been crippling my brain for a while and I really appreciate laying it out for me in a way that isn't presuming I'm some kind of coding god. (I'm really finding lua.org to be less than helpful)

    For reasons unbeknownst to me my addon is no longer erroring on startup. I guess moving some stuff outside of "onload" was enough? Very weird. Anyways, your mention (@Adirelle) of the object based stuff is exactly where I'm sorta stuck at the moment.

    I want to keep all my eggs in one basket, as it were, and have a single source for my 6 profession addons. As it stands child buttons COMPLETELY perplex me I'm trying something different.

    All 6 of my mods will pull from the same 2 functions in the primary file. The problem is that I can't figure out how to tell the primary functions which file is targeting them. Since it will be the same thing on all 5 other mods I'll just show the current text for file 1 and file 2 :).

    http://pastebin.com/SpVp44uQ - This is the first file. It works fine other than some minor bugfixing stuff I need to do for stuff like skinning.

    mas2dev.atlassian.net/browse/DN - This is the second.

    So how can I tell those first 2 functions:

    buttonTextFunction = "TIOS_GetButtonText",
    tooltipTextFunction = "TIOS_GetTooltipText",

    Ignore the (a1) thing I tried. It didn't work >.>...

    Anywho. Is there any way to have the function "send" a variable. Like "A1" and have the original function go "if A1 then return allthemonkeys"

    Alternatively. I could try to build a "DB" out of a table with all 6 professions but so far my attempts to do that have failed miserably. Error codes about truncating things and pissing off LUA.

    Thanks again!

    PS. @Seerah Thanks a ton! That makes a lot more sense to me. I noticed I didn't thank you as well originally.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Hey all!

    So I'm trying to write a dynamic addon that will take your professions in order and put them on titan panel much like the dozen or so individual mods that exist (each explicitly for a different profession).

    The major problem is that obviously wow doesn't cache the professions data on load so the addon crashes during startup. But if you /reload it works fine.

    I'm using the titanstarter template because the last 2 weeks are the extent of my knowledge of Lua. Pretty proud with what I've got thus far.

    But can someone explain this to me? Assume I'm a moron:

    SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)

    What is this doing exactly? I saw it as advice on the wow forums and have paired it with the following stuff. The goal is to grab the addon data after the game loads because I don't want my addon to crash.

    SetScript('OnEvent', function(self, event, ...) self[event](self, ...) end)
    f:RegisterEvent("TRADE_SKILL_UPDATE")
    
    function f:TRADE_SKILL_UPDATE()
    	-- These variables will be used throughout the mod.
    	--Grab the 6 different professions.
    	local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions();
    	--Make a table out of those bad boys.
    	TS.ProfTable = { prof1, prof2, archaeology, fishing, cooking, firstAid }
    	--Get us that sweet information.
    	if ProfTable[1] ~= nil then
    	TS.name, TS.icon, TS.skillLevel, TS.maxSkillLevel, _, _, _, _ = GetProfessionInfo(TS.ProfTable[1]);
    	else
    	TS.name = "NA"
    	TS.icon = "Interface\\minimap\\TRACKING\\Profession"
    	TS.skillLevel = 0
    	TS.maxSkillLevel = 0
    	end
    end


    Since you probably want to see the entire thing:

    http://pastebin.com/QzHkBMXN Edit: Updated to show the script working but not on fresh load. The above code would presumably be put somewhere near the top (if that even matters).

    I'll be going backwards through this thing and removing most of the vestigial stuff from TitanStarter but for the most part this is writing of my own doing.

    I just can't wrap my head around what on Earth is going on in setscript and googling is not helping.

    I get that ... means like "All the things" and self refers to the frame. But that doesn't help my brain process that line of code.

    edit: I'm aware that I had some missing "="'s and a "then" and a superfluous "~=" in the pastebin. I've fixed them on my end >.>... still learning...
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.