I know it shouldn't, but it all depends on the order the calls/functions are declared in the file. For instance if you try to call a local function located below the call, it will be unable to run it (because the program doesn't know the function yet).
In this case it should work I guess... Thanks for the help :-)
If the order gives you headaches, you can define all the function names as local at the start of the file like this:
ADDON_NAME, nameSpace = ...
local firstFunctionName, secondFunctionName, thirdFunctionName
function thirdFunctionName(userInput)
return secondFunctionName(userInput)
end
function secondFunctionName(userInput)
return firstFunctionName(userInput)
end
function firstFunctionName(userInput)
if userInput then
return type(userInput)
end
return false
end
and they all are local scoped (or at least I haven't ran into any global leaking afaik using this method) but you don't have to worry about their order.
TSM probably is trying to do something with the Blizzard_ArtifactUI before the data is available from the server and you end up with these compare with nil errors. You should make a ticket straight to the creator of TSM.
Only reason why it would return false is the fact congrazTable[i] and newLevel being different values and the comparison returns false.
Maybe this would work (untested)?
function partyLevelUp(self, event, unitID)
if (UnitInParty(unitID) and UnitPlayerControlled(unitID)) and not (UnitIsUnit(unitID, "player") and IsInRaid()) and DLUSettings.partyEnabled then
local partyMemberName = UnitName(unitID);
local _, classFileName = UnitClass(unitID);
local newLevel = UnitLevel(unitID);
local congratzTable
local randomCongratz = {"Gratz, %s", "Gz, %s", "Keep it up, %s"};
if (classFileName == "DEATHKNIGHT" or classFileName == "DEMONHUNTER") then
congratzTable = CLASS_TALENT_LEVELS[classFileName];
else
congratzTable = CLASS_TALENT_LEVELS["DEFAULT"];
end
for _, level in pairs(congratzTable) do
if level == newLevel then
print("Level: "..level)
local congratzString = string.format(randomCongratz[math.random(#randomCongratz)], partyMemberName);
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
SendChatMessage(congratzString, "INSTANCE_CHAT");
else
SendChatMessage(congratzString, "PARTY");
end
break
end
end
end
end
local function createLink(id)
local link
link = GetSpellLink(id)
if link == nil or link == "" then
link = string.format("|cff71d5ff|Hspell:%d:|h[%s]|h|r", id, (GetSpellInfo(id)))
end
return link
end
Edit: Totally untested, but hope this workaround helps you anyway.
Edit 2: Maybe
GetSpellLink(GetSpellInfo(id))
could be worth of a try if you want to make it shorter, but it could cause problems by pulling data from different spell with same name.
Hi, I'm writing a loot-wishlist addon for my guild where players can fill their wishlists via EncouterJournal with small buttons I added. One of the feature in the addon is to remove items from wishlist when you get them (if the item is from or above the difficulty you added them to your wishlist).
I check players' equiped gear and items in inventory for to remove from the wishlist and I have ran into few problems with tier sets that I haven't managed to solve by myself. When going through the wishlist to remove items I have to match not only the tokens and the actual items, but also the Essences found in T17.
First problem: When I started coding this addon I wasn't thinking too far into the future and ended up hard coding the tier-items, tokens and essences into tables. Now with the release of T18 I'm asking if anyone of you have a better idea how to match these things so I don't have to waste time looking up and hardcoding tier items to tables with every new tier added into the game?
Second problem: To remove Essences from the wishlist I counted all the tier-items, tokens and essences and removed essences from wishlist if the total number was equal of above pre-set number, but this also counts duplicates, tokens for slots that has already the tier item and unusable tokens also. This isn't that big of a deal, unless you are the guy in the raid who picks and sells all the unwanted gear and your Essence is removed from your wishlist because of you picking all the unwanted tokens. Is there any way to match usability of tier token or should I try to hardcode a table with matching classes and tokens (I'm trying to reduce the amount of hard coding stuff that I have to add every new tier released)?
Here is some code related to my problems:
local TierItems = { -- List of Tier-items and their matching tokens
-- Helm of the Iron Conqueror
[119308] = 119308, -- Token
[115568] = 119308, -- Paladin
[115563] = 119308, -- Priest
[115586] = 119308, -- Warlock
-- Helm of the Iron Protector
[119321] = 119321, -- Token
[115545] = 119321, -- Hunter
[115556] = 119321, -- Monk
[115579] = 119321, -- Shaman
[115584] = 119321, -- Warrior
-- Helm of the Iron Vanquisher
[119312] = 119312, -- Token
[115539] = 119312, -- Death Knight
[115542] = 119312, -- Druid
[115553] = 119312, -- Mage
[115572] = 119312, -- Rogue
-- 8< SNIP, SNIP - you get the idea... --
}
local Essences = { -- List of Essences (Turn-in questitems for Tier-tokens)
-- Essence of the Iron Conqueror
[119310] = true, -- Horde
[120277] = true, -- Alliance
-- Essence of the Iron Protector
[119323] = true, -- Horde
[120279] = true, -- Alliance
-- Essence of the Iron Vanquisher
[119316] = true, -- Horde
[120278] = true, -- Alliance
}
local function _CheckLink(link) -- Return itemID and difficultyID from itemLink
if not link then -- No link given
return
elseif itemLinks[link] and itemLinks[link].id ~= nil then -- Check if we have scanned this item already
return itemLinks[link].id, itemLinks[link].difficulty
end
local _, itemID, _, _, _, _, _, _, _, _, _, difficultyID = strsplit(":", link)
itemID = tonumber(itemID)
difficultyID = tonumber(difficultyID)
itemLinks[link] = { id = itemID, difficulty = difficultyID } -- Add to table for faster access later
return itemID, difficultyID
end
local function _CheckEssence(essenceID, essenceDiff) -- Check if Player has already enough Tier-items
local tokenCount = 0
-- Check Backbags
local bag, slot = 0, 0
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local itemID, difficultyID = _CheckLink(GetContainerItemLink(bag, slot))
if itemID == essenceID and essenceDiff <= difficultyID then -- Essence found
Debug("Backbags: Essence", itemID)
tokenCount = tokenCount + 1
elseif TierItems[itemID] and essenceDiff <= difficultyID then -- Tier-item found
Debug("Backbags: Tier", itemID)
tokenCount = tokenCount + 1
end
end
end
-- Check Equiped
for i = 1, 10 do -- Head (1), Shoulder (3), Chest (5), Legs (7), Hands (10)
if i == 1 or i == 3 or i == 5 or i == 7 or i == 10 then
local itemID, difficultyID = _CheckLink(GetInventoryItemLink("Player", i))
if TierItems[itemID] and essenceDiff <= difficultyID then -- Tier-item found
Debug("Equiped: Tier", itemID)
tokenCount = tokenCount + 1
end
end
end
return tokenCount
end
for i = 1, 17 do -- Skip the shirt (4) and tabard (18)
if i ~= 4 then
local itemID, difficultyID = _CheckLink(GetInventoryItemLink("Player", i))
if db[itemID] and db[itemID].difficulty <= difficultyID then -- Item found, remove from wishlist
Debug("Remove by Equiped:", itemID, difficultyID)
db[itemID] = nil
elseif db[TierItems[itemID]] and db[TierItems[itemID]].difficulty <= difficultyID then -- Tier-item found, remove from wishlist
Debug("Remove Tier by Equiped:", TierItems[itemID], "->", itemID, difficultyID)
db[TierItems[itemID]] = nil
end
end
end
local bag, slot = 0, 0
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local itemID, difficultyID = _CheckLink(GetContainerItemLink(bag, slot))
if Essences[itemID] then -- Essence found, check if we have enough tier already
local essenceCount = _CheckEssence(itemID, difficultyID)
if essenceCount >= cfg.maxTiersForEssence then
Debug("Remove Essence by Bags:", itemID, difficultyID, essenceCount)
db[itemID] = nil
end
elseif db[itemID] and db[itemID].difficulty <= difficultyID then -- Item found, remove from wishlist
Debug("Remove by Bags:", itemID, difficultyID)
db[itemID] = nil
elseif db[TierItems[itemID]] and db[TierItems[itemID]].difficulty <= difficultyID then -- Tier-item found, remove from wishlist
Debug("Remove Tier by Bags:", TierItems[itemID], "->", itemID, difficultyID)
db[TierItems[itemID]] = nil
end
end
end
Bonus problem for anyone interested in hacking EncounterJournal: Currently the wishlist buttons appear in every loot subpage EJ has (old raids, world bosses and dungeons). Is there any easy way to detect when you are looking at actual WoD (and future expansions) raid instance pages that doesn't bomb server with queries when scrolling the loot subpage scroller so I could hide the buttons for dungeons and world bosses?
0
and they all are local scoped (or at least I haven't ran into any global leaking afaik using this method) but you don't have to worry about their order.
0
if it was unclear what to do.
0
TSM probably is trying to do something with the Blizzard_ArtifactUI before the data is available from the server and you end up with these compare with nil errors. You should make a ticket straight to the creator of TSM.
0
Only reason why it would return false is the fact congrazTable[i] and newLevel being different values and the comparison returns false.
Maybe this would work (untested)?
0
Maybe something like this would work?:
Edit: Totally untested, but hope this workaround helps you anyway.
Edit 2: Maybe
could be worth of a try if you want to make it shorter, but it could cause problems by pulling data from different spell with same name.
0
I check players' equiped gear and items in inventory for to remove from the wishlist and I have ran into few problems with tier sets that I haven't managed to solve by myself. When going through the wishlist to remove items I have to match not only the tokens and the actual items, but also the Essences found in T17.
First problem: When I started coding this addon I wasn't thinking too far into the future and ended up hard coding the tier-items, tokens and essences into tables. Now with the release of T18 I'm asking if anyone of you have a better idea how to match these things so I don't have to waste time looking up and hardcoding tier items to tables with every new tier added into the game?
Second problem: To remove Essences from the wishlist I counted all the tier-items, tokens and essences and removed essences from wishlist if the total number was equal of above pre-set number, but this also counts duplicates, tokens for slots that has already the tier item and unusable tokens also. This isn't that big of a deal, unless you are the guy in the raid who picks and sells all the unwanted gear and your Essence is removed from your wishlist because of you picking all the unwanted tokens. Is there any way to match usability of tier token or should I try to hardcode a table with matching classes and tokens (I'm trying to reduce the amount of hard coding stuff that I have to add every new tier released)?
Here is some code related to my problems:
Bonus problem for anyone interested in hacking EncounterJournal: Currently the wishlist buttons appear in every loot subpage EJ has (old raids, world bosses and dungeons). Is there any easy way to detect when you are looking at actual WoD (and future expansions) raid instance pages that doesn't bomb server with queries when scrolling the loot subpage scroller so I could hide the buttons for dungeons and world bosses?
If you want/need to see more code, it is all found at http://wow.curseforge.com/addons/loihloot/