• 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    Also, I'd like to point out that the code in the attachment I posted a few days ago already handles the issue of profession data not being available on login. I even tested it, on multiple characters, some without any professions at all.


    I'll go look at it. Admittedly I hadn't planned to look at it until I figured this stuff out. Ironically* that just made it take longer :p.

    Thanks again.

    *I always say ironically when I mean "amusingly"...bad habit.

    edit: Oh wow yeah, your demo script works perfectly. Feel bad about having you basically make it for me. I'll look over it real intently to learn from your magic.

    My next project is a pet/mount addon, since the ones we were using stopped doing what we wanted them to do. Hopefully what I've learned here will lead to that going smoother :).



    Oh very nice. This'll be handy.

    Edit #2:

    About the only problem I see with your addon demo is that it thinks I'm always in combat once I've been in combat once. I'll see if I can figure it out and have it reset after combat has ended.

    Update:

    local inCombat = not InCombatLockdown() --print("ProfessionBroker", "OnEnter", clickable, profession.name)
    				if not inCombat and profession.id and (profession.action1 or profession.action2) then


    This is why I get the red message.

    not InCombatLockdown is the equivalent of not being in combat. But not not being in combat is in combat so~.

    If I switch it to inCombat = InCombatLockdown() it fixes the erroneous "You are in combat" error message but doesn't make it clickable. Will continue investigating.

    			OnClick = function(this, button) --print("ProfessionBroker", "OnClick", button)
    				print("Oh no!") -- this should never happen
    			end,


    Slapped a print in there to see, it does indeed happen. With or without the combat change above. So I'm guessing the overlay on top of the buttons does not exist. I say guess because there are a lot of new tricks and commands in here that I've never seen before haha. Googling them as I go along.

    Update: Just to be sure I turned off all addons but titan panel and this one and still the issue persists, so its not an addon conflict.

    In my unprofessional opinion I think the problem is at the action1 action2 portion of the script. I am trying to figure it out. I might do one of my "This does X I think" style posts tomorrow. Just so I can know I get it.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Adirelle
    Are you sure you get the concept of variable ?


    I like to think so. I used to write dynamic npcs for Ragnarok Online back in the early 2000's. The vast majority of the values they accessed or displayed were variables. edit: This was around the time I learned how easily it was to make things get exponentially out of control.

    Quote from Adirelle

    t = { 6 } -- create an shelf with one box on it, labeled 1, and put 6 in that box, then put the location of that shelf in the box labeled "t".
    t.foo = 5 -- use the content of the box labeled "t" to find the corresponding shelf then put 5 in the box labeled "foo". If there is no box labeled "foo" on the shelf, create it.



    Ah, I do like thinking of it that way. Bit easier on the brain.

    Quote from Adirelle

    Each time you reload, the Lua interface is completely reset. All the addons are loaded and started again. The subtle difference is that some data may be available at the very start after a /reload because the C code is NOT reset. However, for all intent and purpose, you should consider the case of the first connection, with missing data, because most of people does not want to /reload each time they log in.


    Yeah, it is less than ideal.

    Quote from Adirelle

    So you have the write a piece of code that can handle the lack of information (i.e. nil). This is quite common with wow addons, since most data are not available at loading time.


    Sounds good. I'll go work on that and be back in a bit. I do find it awfully strange that wow addons load before even some of the most basic data loads. You'd think that by default they'd have addons loading last in the chain, certainly after something as personal to the character as their professions.

    But alas, it is what it is.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Adirelle
    i and t are just the variable names I wanted to use inside my "for" loop. They have no other meaning (beside "i" for index and "t" for table, but that's just a convention) and have no use outside of the loop.


    Oh! Suddenly I realize where "professions" came from then in those script examples I was given prior.

    Quote from Adirelle

    Have you given a look at the Lua table tutorial ?


    A few times now, most of the time it looks like Portuguese to me.

    http://lua.gts-stolberg.de/en/generischFor.php - I found this page ever so slightly more helpful on helping me wrap my brain around it.

    Edit:

    tinsert(ProfTable, { id = id, id.name = name, id.icon = icon, id.skillLevel = skillLevel, id.maxSkillLevel = maxSkillLevel })

    So this would mean that the 6 responses would be:

    ProfTable[1].id = id
    ProfTable[1].name = name
    etc etc.

    So if Skinning is my first profession it says:

    ProfTable[1].id = prof1
    ProfTable[1].name = Skinning

    If that is true then lets walk through that other part and see where I'm going wrong:

    frame:RegisterEvent("TRADE_SKILL_UPDATE") -- For testing, I can open a skill to immediately fire the script.


    frame:SetScript("OnEvent", function(self, event, ...) -- Every time I open a skill anything in this block fires.
    	for id = 1, #ProfTable do -- Start at 1, then keep adding 1 until we hit a nil or NaN point.


    local profession = ProfTable[id] -- Each time the script runs it makes the word "profession" equal to the current table identifier. So profession on the first run is the same as typing ProfTable[1].


    local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(profession.name) -- This grabs the information of whatever profession we have. In this case it would be GetProfessionInfo(Skinning)


    if profession.name = prof1 or prof2 or archaeology or fishing or cooking or firstAid then -- Checks to see if ProfTable[1].name is the same as any of these values, which it should be since those are the only 6 possible outcomes.


    Let's assume that it finds that profession.name does indeed equal one of those values. It then does the following:

    profession.name = name -- This is the same as ProfTable[1].name = name or more specifically ProfTable[1].name = Skinning
    
    profession.label = name -- ProfTable[1].label = Skinning
    
    profession.icon = icon -- ProfTable[1].icon = file directory location of the icon.
    
    profession.text = format("%d/%d", skillLevel, maxSkillLevel) -- A text printing of the min/max skill levels of ProfTable[1].text.


    So then we jump back to the actual LibStub:

    for id, profession in pairs(ProfTable) do
    	profession.plugin = LibStub("LibDataBroker-1.1"):NewDataObject("TheIOSLibTest"..id, {


    This part is hard for me to visualize but let's try?

    ProfTable[profession] = 1 (on the first run, 2 on the second run, etc).

    This feels wrong. I just can't read that line I guess.

    profession.plugin becomes the LibStub frame/object named "TheIOSLibTest1" then "TheIOSLibTest2" and so on.

    Now where or how is the addon figuring out what profession equals on the first run, as opposed to the /reload run.

    We haven't told it that profession = ProfTable[id] until a piece that can only be accurate the second time we run it?

    I feel like the object is looking at a different location than we are creating, which is why the tooltip is always failing to find its target (it gets pissy about concatinating "name").

    http://pastebin.com/ViSUC3wJ

    I'm trying my best to figure this stuff out before I end up aggravating you guys :p. But I feel like the "pointers" going on here are a tier above my understanding.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Adirelle
    (remember that nil means not-in-list)


    I thought you were pulling my leg. Looked this up and apparently in coding it really does mean "not in list". Fascinating, has become the office trivia of the day.

    Quote from Adirelle

    local someTable = {}
    tinsert(someTable, { id = 25 })
    tinsert(someTable, { id = 2 })
    tinsert(someTable, { id = 1 })
    for i, t in ipairs(someTable) do
      print(i, t.id)
    end
    -- Prints:
    -- 1 25
    -- 2 2
    -- 3 1
    


    So in this example I presume that "t" is short for whatever the name of the table is? Or does Lua assign the name of the table to t when using the function in this manner?

    I suppose while I wait for a response I'll get off my duff (metaphorically speaking, I fell down the stairs and don't care to walk more than I need to) and find out for myself.

    Thanks!

    Edit:

    With your guidance in mind I was thinking, if the table are random shouldn't this:

    tinsert(ProfTable, { id = id, id.name = name, id.icon = icon, id.skillLevel = skillLevel, id.maxSkillLevel = maxSkillLevel })


    Make it finally work with:

    local profession = ProfTable[id]
    	local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(profession.id)
    	local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
    		if prof1 or prof2 or archaeology or fishing or cooking or firstAid then
    		profession.id = id
    		profession.name = name
            profession.label = name
    		profession.icon = icon
            profession.text = format("%d/%d", skillLevel, maxSkillLevel)


    My reasoning being that EVEN if the table is randomized, the values now are assigned "professionname.value" which means they should always overlap?

    I wish I could test now but looped addons are too much for this terrible office laptop of mine hah. At least it can run a text editor >.>...
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    I realize I can't wrap my head around the pairs function. Could you explain it to me? I'm trying to troubleshoot the last part of this addon (the event portion) and for the life of me I can't "read" well enough to fix it.

    First we'll start with what I have, this is like the 20th iteration and all of them have had the same result. Which probably is because I don't get pairs yet.

    Basically I want to make it set permanent variables like we discussed but I'm apparently just not "getting it".

    local ProfTable = {}
    


    This gives us our table to start filling up.

    local function AddProfession(id)
            if id then
                    local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(id)
                    tinsert(ProfTable, { id = id, name = name, icon = icon, skillLevel = skillLevel, maxSkillLevel = maxSkillLevel })
            else
                    tinsert(ProfTable, {})
            end
    end
    


    This either populates the table with the information for the professions (which will only happen on reload because on startup there is no information) or it keeps the table empty. My question is, for those empty sections is it creating any information? Like a blank table associated with that id? I would suppose not because we've not included anything in the brackets.

    local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
    
    AddProfession(prof1)
    AddProfession(prof2)
    AddProfession(archaeology)
    AddProfession(fishing)
    AddProfession(cooking)
    AddProfession(firstAid)
    


    Here we are just pulling the "names" that each of these variables is associated with. Running through the script up top and filling in the table accordingly.

    for id, profession in pairs(ProfTable) do
    	profession.plugin = LibStub("LibDataBroker-1.1"):NewDataObject("TheIOSLibTest"..id, {
    


    So these frames are called "TheIOSLibTest1" through 6? Or "TheIOSLibTestSkinning" through FirstAid?

    local frame = CreateFrame("Frame")
    --frame:RegisterEvent("SKILL_LINES_CHANGED")
    frame:RegisterEvent("TRADE_SKILL_UPDATE")
    --frame:RegisterEvent("WORLD_MAP_UPDATE")
    frame:SetScript("OnEvent", function(self, event, ...)
    


    Creates a frame, then registers events, then it says "This frame fires on event, which event? All of them inside this block."

    	for id = 1, #ProfTable do
    


    So this is the same as the "i=whatever, increment by whatever, do this" thing that I've been using before. I assume that the pound sign is just telling Lua that ProfTable is a table.

    	local profession = ProfTable[id]
    


    This makes the variable "profession" the name of our Profession Table related to the id we are currently on. So if I type "profession.id" it would grab ProfTable[id].id which SHOULD pull from the stuff at the top. In fact it does appear to do so on a reload.

    	local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(profession.id)
    


    This was me seeing if it worked. Figured if it did then great!

    local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
    if prof1 or prof2 or archaeology or fishing or cooking or firstAid then
    


    First we grab the profession info (just to be safe, since this stuff doesn't want to work). Then we say "IF one of these things is true, proceed." My problem with this idea is that it doesn't seem to differentiate between trying to update profession #3 when I have profession #1 (since that would satisfy the or statement). Perhaps you see something with this that I don't.

    		profession.id = id
    		profession.name = name
            profession.label = name
    		profession.icon = icon
            profession.text = format("%d/%d", skillLevel, maxSkillLevel)
    


    If those things are true do this!

    		else
    		profession.name = "Broken"
            profession.label = "Broken"
    		profession.icon = "Interface\\Icons\\INV_Misc_QuestionMark"
            profession.text = format("%d/%d", 0, 0)
    		end
        end
    end)


    If those things are not true, do this. Just so things don't break.

    But here is the thing :(. This isn't working. So I suppose learning about pairs and then maybe educating my errors on this stuff will help me move along.

    Also a PS, any idea how to move these to "Professions" on titan panel?
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    Some investigation has revealed that SKILL_LINES_CHANGED is the one and only event you need to care about. It fires when you learn or unlearn an entire profession, when you learn a new profession skill, and when you gain skill points in a profession.


    Yeah I had come to a similar conclusion while testing in timeless isle. I was using the other two for quick testing (pressing m or opening tradeskill window is pretty fast).

    Quote from Phanx

    Rather than creating a table like that, you can just check the variables directly:

    if prof1 or prof2 or archaeology or fishing or cooking or firstAid then
         -- at least one profession is known
    end



    I'm a little bothered I didn't think of that myself. It seems really obvious in hindsight. But I'll be the first to admit it would have been days till I came to that conclusion on my own.

    Quote from Phanx
    This is better than only checking the first profession anyway, since it's possible for a player to have learned one or more secondary professions without learning any primary professions.


    Something I hadn't considered at all.

    Quote from Phanx

    you shouldn't touch it unless you really, really know what you're doing.


    So don't touch it. Got it, because if there is one thing that does not describe my understanding of Lua it would be "really, really knowing."

    Quote from Phanx

    (On a side note, you may want to use a name like index or just i there instead of id so you don't get it confused with the actual profession ID, which is stored in profession.id there.)


    I have found that I've been getting turned around because of that, so I think you are probably on the right path by suggesting that.

    Quote from Phanx

    Actually on further investigation, you can use CastSpellByName in an addon, but only to open a profession window. You still can't use it for other profession-related spells, like Survey or Disenchant. So, you can either drop support for those things, or you can add some* additional complexity to make an invisible secure button that gets positioned over the plugin when you mouseover it, so that when you click, you're actually clicking the secure button instead of the plugin.


    Yeah it only seems to error on the "Secondary abilities" which is things like you mentioned. It's a secondary thought so I may end up not doing it but that being said I really like learning and have come a long ways since I got here (even though its been mostly editing your stuff I have been learning while doing so, similar to how I learned Japanese by using a cheat sheet, considerably faster than when I tried to learn it the conventional way).

    Thanks again! I'm gonna try these new methods and see what happens. If all my characters turn into Tuskens I'll be back.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    The keys in ProfTable are not the profession IDs; they're indices, as your print statement showed you.

    The problem is that you're not adding the profession ID to the info table (well, that's my fault, actually, because I wrote that part). You can fix this by modifying the AddProfession function to store the id in the info table for each profession. Also, after a bit more thought, I think you should just use an empty table as the placeholder for professions you haven't yet learned.


    *googles indices*

    Ohhhh.

    Yeah I figured I needed to add it to the table but in trying to do so I pissed off wow really bad.

    Quote from Phanx

    local function AddProfession(id)
            if id then
                    local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(id)
                    tinsert(ProfTable, { [COLOR="Purple"]id = id,[/COLOR] name = name, icon = icon, skillLevel = skillLevel, maxSkillLevel = maxSkillLevel })
            else
                    tinsert(ProfTable, [COLOR="purple"]{}[/COLOR])
            end
    end



    Cool I know what's going on here. Well let's not use a word so strong as "know" but I get the jist.

    Quote from Phanx

    Then your update routine needs to check the ID. On a side note, pairs returns the keys/values in undefined order. If you are working with keys that aren't indices, pairs is the only way to go. However, for an indexed table, you don't need to use pairs, as it's much faster to just iterate over the indices using a simple loop, plus you will get them in order. (You may see the ipairs function being used to retrieve index/value pairs in order -- this function does not do anything that the method shown below does not also do, and it's much slower, so there is no reason ever to use it.)


    Yeah I remember reading about this. Lua doesn't maintain integrity or some such. There is no guarantee of order.

    Quote from Phanx

    local frame = CreateFrame("Frame")
    frame:RegisterEvent("SPELLS_CHANGED")
    frame:RegisterEvent("TRADE_SKILL_UPDATE")
    frame:RegisterEvent("WORLD_MAP_UPDATE")
    frame:SetScript("OnEvent", function(self, event, ...)
    	[COLOR="purple"]for i = 1, #ProfTable do[/COLOR] -- # is the length operator, and provides the number of indices in the table
    		[COLOR="purple"]local profession = ProfTable[i][/COLOR]
    		[COLOR="purple"]if profession.id then[/COLOR] -- don't try to to update unlearned professions
    			local plugin = profession.plugin
    			local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo([COLOR="Purple"]profession.[/COLOR]id)
    			plugin.label = name
    			plugin.icon = icon
    			plugin.text = format("%d/%d", skillLevel, maxSkillLevel)
    		[COLOR="purple"]end[/COLOR]
    	end
    end)



    Played with this enough the last day or so that I've got this one down. Cool.

    Edit: On a glance though I'm not sure how this would ever return anything besides nil once the first table asserts everything as blank on load :).

    Quote from Phanx

    Also, this is another problem:
                    OnClick = function(self, button)
                            if button == "LeftButton" then
                                    if profession.name == "Mining" then CastSpellByName("Smelting")
                                            elseif profession.name == "Skinning" 
                                                    or profession.name == "Herbalism" 
                                                            or profession.name == "Fishing" 
                                                                    then print(profession.name .. " has no spell.")
                                                                            else CastSpellByName(profession.name) end 
                            elseif button == "RightButton" then
                                    if profession.name == "Cooking" then CastSpellByName("Cooking Fire")
                                            elseif profession.name == "Archaeology" then CastSpellByID("80451") -- Survey
                                                    elseif profession.name == "Inscription" then CastSpellByName("Milling")
                                                            elseif profession.name == "Jewelcrafting" then CastSpellByID("31252") -- Prospecting
                                                                    else print(profession.name .. " has no secondary spell.") end
                            end
                    end,

    Confusing formatting aside, that will trigger an error, because addons are not allowed to call CastSpellByName or CastSpellByID. If the API reference you are using doesn't make note of this, get a new API reference. Both Wowpedia and WoW Programming will tell you if a function is protected.


    Yep! I read up on tainted watchamacallits because I saw the error. That confusing formatting is just what I do when I first make something because it makes it easier for my eyes to read it all. It usually doesn't stay that way.

    I'll figure the problems with this. I was tempted to just "cheat" and see if I could send the equivalent slash command, like how the original example did it with afk.

    edit:

    Ok so I've got almost all the way there :p. Since it was always returning nil before I have it checking your life profession status as opposed to the status on login.

    http://pastebin.com/Pf1QYBPK

    Yes I know, I used a variable, I'll change that to something more clever later >.>... I just want it to work first before professionalism.

    Now my problem is that onclick and ontooltip don't see this information. I'm guessing because they aren't using the same frame name, tooltip and self respectively instead of id. But really I'm talking out my butt there.

    I've tried a variety of combinations of variables to see if I could find where profession.name from the tooltip is pulling (or onclick). When I get home I'll contemplate it some more and see what I can do.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    local frame = CreateFrame("Frame")
    frame:RegisterEvent("SPELLS_CHANGED") -- you'll have to figure out which one to use
    frame:RegisterEvent("TRADE_SKILL_UPDATE") -- you'll have to figure out which one to use
    frame:SetScript("OnEvent", function(self, event, ...)
    	for id, profession in pairs(ProfTable) do
    		local plugin = profession.plugin
    		plugin.text = format("%d/%d", profession.skillLevel, profession.maxSkillLevel)
    	end
    end)
    


    So the rest of the script works. But for the life of me this doesn't appear to do anything? If I put a "print" there it prints 6 times as you'd expect but I don't think this is targeting the right place?

    I've been screwing around but I'm not sure. Here is what I've got so far, minus this part not working for me.

    http://pastebin.com/WUBqZkqu

    I'm going to do some prints to see if I can figure out if the tables its trying to update down there is the same as the ones created up top.

    Otherwise thanks again! For the most part I think I understand like 90% of this thing! Maybe even more :o.

    edit: by "not do anything" I mean I don't think its targeting the right place. It DOES fire when you open a trade skill.

    edit: Yet on reload it DOES appear to do something. Very interesting... Will keep plugging away at it. I can't see any reason why it wouldn't work, it should be targeting the same place with that pairs ditty.

    edit #2: It occurs to me that the reason its likely doing nothing is that nowhere in that chunk is it actually pulling the new data. I'll read your post on tables again to see if I can figure it out. I know scuttling the tinsert script from login causes a memory full problem because (I presume) it loops or something.

    Update:

    local frame = CreateFrame("Frame")
    frame:RegisterEvent("SPELLS_CHANGED")
    frame:RegisterEvent("TRADE_SKILL_UPDATE")
    frame:RegisterEvent("WORLD_MAP_UPDATE")
    frame:SetScript("OnEvent", function(self, event, ...)
    	for id, profession in pairs(ProfTable) do
    		local plugin = profession.plugin
    		local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(id)
    		plugin.label = name
    		plugin.icon = icon
    		plugin.text = format("%d/%d", skillLevel, maxSkillLevel)
    	end
    end)


    When I do this I find that it only updates the first and the last profession, leaving the middle ones all nil. If I tell it to print it says "nil, nil, nil, nil, first aid, herbalism." Which are my last and first respectively.

    YET. When I do "print(id)" it does 1,2,3,4,5,6.

    So I am quite perplexed.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    For event handling, you do need a frame, as LDB doesn't do that part for you. Here's what I'd use after the part from your previously-posted code where you start crying. :p


    But luckily I can use frames without XML >.>.

    Quote from Phanx

    The other concern is that profession info isn't available immediately when your addon is loading, so you'd need to delay populating ProfTable and creating the data objects until that information is available. Someone else may know offhand which event you should use for this, but here's a quick testing snippet you can use to find out for yourself:


    Yep! This has been a thorn in my side and the reason you'll notice in my original pastebins I had "nil" return the profession book, 0/0 and no profession name. The problem was that titan panel is a right asshole and won't let you change the icon image after the addon is loaded.

    Quote from Phanx

    Finally, your current code will probably break on learning/unlearning a profession. You may want to adjust the AddProfession function so that, eg. t[2] is always your secondary profession, t[6] is always First Aid, etc. and then just use placeholder data for professions the player hasn't yet learned:


    Yeah that's one of the places where I hadn't tested or even thought to test. This addon is likely going to only be for my Wife and I since we are tired of having 15 ish mods for professions.

    Thanks for your response, it is way more detailed than I was expecting. I'll be spending the night looking over it closely so that I can learn from it. Your work is much easier to read than the addons I was using for guidance as I started learning.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Alright I've hit my last hurdle to finish this project! Your help has been invaluable and saved me weeks of smashing my head into a wall. I'm sold on LibStub.

    How do I add an event to it? I'm not entirely clear. Basically I want to add a PLAYER_ENTERING_WORLD event (or something else, find one that works best later, that's not my concern) but I'm not sure where or how to register the events with ldb and then to call them.

    --[[ Here we create the table base. ]]--
    local ProfTable = {}
    --[[ Next we build a function called AddProfession, which will build a table centered around an id which is determined by functions. ]]--
    local function AddProfession(id)
    	if id then
    		local name, icon, skillLevel, maxSkillLevel = GetProfessionInfo(id)
    		ProfTable[id] = { name = name, icon = icon, skillLevel = skillLevel, maxSkillLevel = maxSkillLevel }
    	end
    end
    --[[ Next we pull a temporary variable containing the profession information of each profession into their respective name. ]]--
    local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions()
    --[[ Finally we call the function at the beginning of this comment chunk and fill in the "id" with the profession information we just pulled into local vars. ]]--
    AddProfession(prof1)
    AddProfession(prof2)
    AddProfession(archaeology)
    AddProfession(fishing)
    AddProfession(cooking)
    AddProfession(firstAid)
    --[[ Lastly we weep at the beauty that is this code. Thanks to Phanx for this chunk! ]]--
    
    --[[ Change this value to one of the 6 above for each of the mods. ]]--
    iosprof = prof1
    
    local plugin = LibStub("LibDataBroker-1.1"):NewDataObject("TheIOSLibTest", {
    	type = "data source",
        text = "0 / 0",
        icon = [[Interface\minimap\TRACKING\Profession]],
        label = "",
        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("You are AFK: |cffffffff" 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,
    end)
    })
    
    --[[    
    	For when I figure out the on event thing, these work absolutely fine. All tested.
    	text = ProfTable[iosprof].skillLevel .. "/" .. ProfTable[iosprof].maxSkillLevel,
        icon = ProfTable[iosprof].icon,
        label = ProfTable[iosprof].name
    	]]--


    Naturally I'll learn the menu stuff on my own, it looks pretty straight forward. I also intentionally left label blank :). Basically by default the game will just show a professions booklet and then after the "event" it will update those pieces to the values in the comment bracket at the bottom (which I tested and works perfectly).

    Thanks!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx

    Also, you do not need XML to create a frame, or for anything else. The only reason to use XML is if you are creating templates (virtual frames) to pass to secure headers.


    So I learned! I'm super happy about this! I hate xml, the amount of tags involved is just horrifying to me. I can't stand any language that is that messy.


    Quote from Phanx

    Files are read and processed in the order they are listed. Your addon depends on LDB, so you need to list LDB first, so that it gets loaded before your addon. Also, LDB depends in turn on LibStub and CallbackHander, and CallbackHandler depends on LibStub, so you need to load both of those in the proper order, too.


    Whoa. I had no idea about this. Thanks!

    Quote from Phanx

    Also, the function named "GetProfessionInfo" is indeed part of the WoW API, not part of the Lua language.


    Darn! I felt smart for a second ;).
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Edit: FIXED IT. I noticed in documentation that the addonname must be in quotations :D. I'm an adult! Will edit here instead of making a new post if anything new comes up.

    But the addendum to that is that while it works the db.note triggers an error currently. Otherwise I'm adapting my addon to this as you read this if you are reading this in the past, which you aren't, so I'm probably already done.

    Alright so, ldb education time for muah. I'm guessing my problem is that I haven't added an XML for this or set a frame.

    local plugin = LibStub("LibDataBroker-1.1"):NewDataObject(TheIOSLibTest, {
        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,
    })


    This example from before paired with this TOC

    TheIOSLibTest.lua
    libs\LibDataBroker-1.1


    Leads to this error:
    Date: 2014-02-06 15:21:47
    ID: 1
    Error occured in: Global
    Count: 1
    Message: ...s\Archy\Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua line 48:
       table index is nil
    Debug:
       ...s\Archy\Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua:48: NewDataObject()
       TheIOSMod\TheIOSLibTest.lua:2: in main chunk


    Full pastebin of this monstrosity found here:

    http://pastebin.com/jAjuvPxR

    I'm not sure where to even begin with that issue haha. Is it because db.note isn't covered anywhere?

    If I turn off the addon the NEXT addon using the libraries fails, ad infinitum. The first was tomtom.

    While I'm here I'll ask you a question about your other guidance.

    for professionID, professionInfo in pairs(ProfTable) do
        print(professionInfo.name)
    end


    Ok so I was about to ask a question about this and then I realized that the "get" in "get professioninfo" is not a wow command but a lua command that is "getting" the data from "professioninfo".

    Holy cow, it is weird how just preparing to ask about it makes it click for me...
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Wow that's beautiful. I hadn't actually dived into pairs yet. I'm a producer working with a dev team, so I've heard them mention it before but I hadn't thought about it for this.

    I didn't realize you could check for nil just by asking for the variable.

    for example "if prof2 then tinsert(ProfTable, prof2) end" just kinda blew my mind.

    I might need to invest in a mop, because there is mind all over the place.

    I'll go dabble some more and won't be back until this is done and everything is moved off the Titan API.

    Thanks!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Hey I can't edit my last post but I'm interested in if you think I'm doing this the cleanest way (apologies for double post, my last post gives me an error saying it has 5 pictures in it?)

    --[[ This is where we test my script to see if it works! ]]--
    -------------------------------------------------------------
    SLASH_IOSMOD1, SLASH_IOSMOD2 = '/ios', '/iosmod';
    function SlashCmdList.IOSMOD(msg, editbox)
    -------------------------------------------------------------
    
    		--This finds out which professions the player has. The line following adds those non-nil values to a table.
    		local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions();
    		ProfTable = { prof1, prof2, archaeology, fishing, cooking, firstAid }
    		ProfName = { }
    
    		--This loop checks if each value is nil or not. For non-nils it gathers the information about them then saves them to our ResultTable table.
    		for i = 0, 6, 1 do
    		if ProfTable[i] ~= nil then
    		local name, icon, skillLevel, maxSkillLevel, _, _, _, _ = GetProfessionInfo(ProfTable[i]);
    		ProfName[i] = name
    		ProfName[i].icon = icon
    		ProfName[i].skillLevel = skillLevel
    		ProfName[i].maxSkillLevel = maxSkillLevel
    		print("" .. ProfName[i] .. " ".. ProfName[i].skillLevel .. " / " .. ProfName[i].maxSkillLevel .. ""); -- This is just my printer so I can see in game what is being saved or if the variables are being called correctly.
    		end
    	end	
    end


    So if I understand this correctly. Let's say I do this with Billdabear on Uldum.

    ProfName[1] should return "Mining".
    ProfName[1].skillLevel should return "133".
    and so on.

    ProfName[1].skillLevel being the same as Mining.skillLevel?

    My question is. Is there a cleaner way to do this? I'd like to learn how to do things more professionally but my primary concern is to first learn how to do things at all ;). So I suppose in 30 minutes I'll have my answer when I test this in game.

    Thanks again for all the help and I'm doing my best not to pester you guys when I can figure something out on my own. But my experience with Ragnarok back in the day was that I was really good at making anything work because I'm willing to brute force my way to success, but inevitably it meant someone who took the time to learn better and be taught better could redo what I brute forced in considerably less lines.

    I don't MIND that strategy of just hulking out until it works, but I'd like to be a bit more professional.

    I figure if this works, then I can build an array of all 6 professions (non-nil) and have the nils default to my "professions book and no text" alternative. Then I can implant that stuff (properly) into the newobject thing from libstub and be gravy train.

    I'm curious if I can overcome titan panels terrible support for child buttons and use libstub to create a single addon that has unique onclicks for each of the pieces.



    So I like that it works but I want to reduce it from 6 addons to 1 because reasons. But the child button feature on titan panel is like...good lord. Is there a single line of documentation on it? Anywhere? I had to go back a billion revisions of TP just to find it being used on titangold.

    ANYWHO, Presumably with LibStub I can do it because I won't be locked into their restrictive button system (maybe?)

    I'm hoping ElvUI can interact with this stuff too because I use that now and I'd love to port this dealy to that as well (and maybe get rid of TP if I find that I can move everything I love from it into addons for Elv.

    edit: Tested it and nopers! Says I'm trying to index a string value. Time to figure this out :p.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Explaining this SetScript to an idiot.
    Quote from Phanx
    major is a variable whose value is (in this case) a string. However, its value could be any type of thing, as the square brackets just tell Lua to use its value as the name of a table key. self is the library object itself -- a simple table, really -- and minors is a key in that table, whose value is another table in which the value of major is a key. The line you quoted sets its value to the value currently held by the variable minor.


    Ah alright. That makes more sense to me in the morning after a bit of coffee than it did yesterday.

    Quote from Phanx
    self = {
         ["minor"] = {
              ["CallbackHandler-1.0"] = 6
         }
    }
    


    I have this tickling in my gut that tells me that this just helped me learn how I can build a table out of the values from the following script:

    
    		local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions();
    		ProfTable = { prof1, prof2, archaeology, fishing, cooking, firstAid }
    		
    		for i = 0, 6, 1 do
    		if ProfTable[i] ~= nil then
    		local name, icon, skillLevel, maxSkillLevel, _, _, _, _ = GetProfessionInfo(ProfTable[i]);
    		print("" .. name .. " ".. skillLevel .. " / " .. maxSkillLevel .. "");
    		end
    


    I couldn't figure out how to make the table so that the profession "name" could then be used to reference icon, skillLevel, and maxSkillLevel (ie. name.icon would get me the icon for archaeology if that was the name pulled).

    I'll screw around more at lunch but I think I can do it now after seeing your example above. (Not to derail the conversation about libs, was just kind of an epiphany moment).

    Quote from Phanx

    Yes. When you create a library using LibStub, you pass it a major version (a string, typically composed of the library's name and major version, eg. "CallbackHandler-1.0") and a minor version (a number, often an SVN revision number, or sometimes a number that the library's author manually increments each time they make a change to the library).


    I'm guessing these kind of things are more important for people building libraries that they expect other people to use. Since it sounds like LibStub uses like a localized SVN or some such.

    Quote from Phanx

    Not quite. Local variables in Lua are available in the scope where they are defined, and in any lower/deeper scope, eg:


    Is deeper considered by a north to south relationship? This is the case in the other languages that I've written in but none of them had this object system that I noticed.

    Quote from Phanx

    local a = "apple"
    -- a exists here
    
    do
        local b = "banana"
        -- a and b both exist here
    
        do
            -- a and b both exist here too
        end
    
        local a = "pineapple"
        -- b is still "banana", but a is now "pineapple" until this variable goes out of scope
    
        do
            -- b is still "banana" and a is still "pineapple"
        end
    end
    
    -- b no longer exists out here
    -- a is "apple" again
    



    Ah ok, that's basically what I assumed but I expressed it poorly. Cool.

    Quote from Phanx
    You can't just randomly put end keywords in places


    If only I kept revisions of all the attempts at my addon. You'd see that I'm more than capable of putting end randomly all over the place. Wow is more than capable of crashing the addon when I loadup too. I've gotten better though through the power of grayskull (ie. notepad++ with Lua on)

    Quote from Phanx

    You expressed an interest in understanding how LibStub works, so I think that was what he was trying to show you. :p

    Up until that point I had no idea what I was asking. But now I think I've got an idea of what is going on.

    Quote from Phanx

    However, for simply creating a DataBroker plugin, you don't need to create a library, you don't need to do anything with LibStub or CallbackHandler directly, and you all you need to do with LibDataBroker is call its NewDataObject method.


    Thanks :D. This in particular is the bit I needed to know, because when you just walk in on LibStub's stuff without any context its kinda scary.

    Quote from Farmbuyer
    The table created there is what gets filled out by the calling code to eventually become a library table. But as others have said, you don't need to understand how internal combustion motors work in order to learn to drive a car. :-) All this is just an example of very compactly-written Lua code squeezed into a few lines.


    Ohhhh. I think I get that now. Fascinating, yeah I was wondering if this was a mechanic/motorist kind of situation. Though ironically I have been learning recently how to do car repairs because I can't afford to keep paying a mechanic a trillion dollars to do something as simple as a break pad replacement >.>...

    Thanks All! I'm gonna dive into this stuff more today and see what I can manage :).
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.