WoW:API GetStatistic: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Preloading)
 
m (Move page script moved page API GetStatistic to API GetStatistic without leaving a redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{wowapi}} __NOTOC__
{{wowapi}} __NOTOC__


<!-- Describe the purpose of the function, exhausting detail can be saved for a later section -->
Return the value of the requested Statistic.
Return the value of the requested Statistic.
<!-- List return values and arguments as well as function name, follow Blizzard usage convention for args -->
 
  value = GetStatistic(achievementID)
  value = GetStatistic(achievementID)


== Arguments ==
== Arguments ==
<!-- List each argument, together with its type -->
* achievementID (number) - The ID of the Achievement
:(achievementID)
 
:;achievementID : Integer - The ID of the Achievement
 


== Returns ==
== Returns ==
* value (string) - The value of the requested Statistic.


:;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.


== Details ==
== Example ==
<!-- Details not appropriate for the main description can go here.  
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.
    REMOVE the section if you're just going to restate the intro line! -->


: Using the achievementID's of actual Achievements, as opposed to statistics, generates strange results.  More testing is needed.
<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>

Latest revision as of 04:46, 15 August 2023

WoW API < GetStatistic

Return the value of the requested Statistic.

value = GetStatistic(achievementID)

Arguments[edit]

  • achievementID (number) - The ID of the Achievement

Returns[edit]

  • value (string) - The value of the requested Statistic.

Details[edit]

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

Example[edit]

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