WoW:API GetStatistic: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (stub for testing results)
No edit summary
Line 23: Line 23:


: Using the achievementID's of actual Achievements, as opposed to statistics, generates strange results.  More testing is needed.
: Using the achievementID's of actual Achievements, as opposed to statistics, generates strange results.  More testing is needed.
== Example ==
Here is a function that will take any statistic category (like <code>Battlegrounds</code>) and any statistic title in that category (like <code>Battlegrounds played</code>) and will return the statistic ID for that statistic, so it can be used in other functions.
<pre>
function GetStatisticId(CategoryTitle, StatisticTitle)
local str = ""
for _, CategoryId in pairs(GetStatisticsCategoryList()) do
local Title, ParentCategoryId, Something
Title, ParentCategoryId, Something = GetCategoryInfo(CategoryId)
if Title == CategoryTitle then
local i
local statisticCount = GetCategoryNumAchievements(CategoryId)
for i = 1, statisticCount do
local IDNumber, Name, Points, Completed, Month, Day, Year, Description, Flags, Image, RewardText
IDNumber, Name, Points, Completed, Month, Day, Year, Description, Flags, Image, RewardText = GetAchievementInfo(CategoryId, i)
if Name == StatisticTitle then
return IDNumber
end
end
end
end
return -1
end
</pre>

Revision as of 07:31, 13 November 2009

WoW API < GetStatistic

Return the value of the requested Statistic.

value = GetStatistic(achievementID)

Arguments

(achievementID)
achievementID
Integer - The ID of the Achievement


Returns

value
String - The value of the requested Statistic.

Details

Using the achievementID's of actual Achievements, as opposed to statistics, generates strange results. More testing is needed.

Example

Here is a function that will take any statistic category (like Battlegrounds) and any statistic title in that category (like Battlegrounds played) and will return the statistic ID for that statistic, so it can be used in other functions.

function GetStatisticId(CategoryTitle, StatisticTitle)
	local str = ""
	for _, CategoryId in pairs(GetStatisticsCategoryList()) do
		local Title, ParentCategoryId, Something
		Title, ParentCategoryId, Something = GetCategoryInfo(CategoryId)
		
		if Title == CategoryTitle then
			local i
			local statisticCount = GetCategoryNumAchievements(CategoryId)
			for i = 1, statisticCount do
				local IDNumber, Name, Points, Completed, Month, Day, Year, Description, Flags, Image, RewardText
				IDNumber, Name, Points, Completed, Month, Day, Year, Description, Flags, Image, RewardText = GetAchievementInfo(CategoryId, i)
				if Name == StatisticTitle then
					return IDNumber
				end
			end
		end
	end
	return -1
end