Thread Tools Display Modes
04/02/15, 01:07 AM   #1
hisdad
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 33
GetRecentlyCompletedAchievements() Advice on returns

Hi,
I'm baffled by this, as the return type seems strange.
What I want to do is dump out all a chars achievements and then iterate over them.
d() tells me it does something, but I'm unsure what..

Any advice greatfully received.

--Dad
  Reply With Quote
04/02/15, 05:20 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
It returns a dynamic list of achievement-ids.

Lua Code:
  1. local max_returned = 6
  2. local achievementIds = {GetRecentlyCompletedAchievements(max_returned)}
  3. for i=1,#achievementIds do
  4.   local achievementId = achievementIds[i]
  5.   local name = GetAchievementInfo(achievementId) -- See WIKI for more
  6.   d(name)
  7. end
(untested)
  Reply With Quote
04/02/15, 01:43 PM   #3
hisdad
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 33
Getting ALL Achievements..

Originally Posted by votan View Post
It returns a dynamic list of achievement-ids.

Lua Code:
  1. local max_returned = 6
  2. local achievementIds = {GetRecentlyCompletedAchievements(max_returned)}
  3. for i=1,#achievementIds do
  4.   local achievementId = achievementIds[i]
  5.   local name = GetAchievementInfo(achievementId) -- See WIKI for more
  6.   d(name)
  7. end
(untested)
Thx Votan,
It works with the problem that no matter how many I want (9999) it returns a max of 10.
Is there a better way of doing this?

--Dad
  Reply With Quote
04/02/15, 02:16 PM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
That's using offical API functions:
Lua Code:
  1. local function GetAll()
  2.   local function GetAchievements(topLevelIndex, categoryIndex, numAchievements)
  3.     for achievementIndex=1,numAchievements do
  4.       local achievementId = GetAchievementId(topLevelIndex, categoryIndex, achievementIndex)
  5.       local _, _, _, _, completed = GetAchievementInfo(achievementId)
  6.       while achievementId ~= 0 do
  7.         d(achievementId)
  8.         achievementId = GetNextAchievementInLine(achievementId)
  9.       end
  10.     end
  11.   end
  12.  
  13.   local numCategories = GetNumAchievementCategories()
  14.   for topLevelIndex=1,numCategories do
  15.     local _, numSubCatgories, numAchievements = GetAchievementCategoryInfo(topLevelIndex)
  16.     GetAchievements(topLevelIndex, nil, numAchievements) -- General
  17.     for subCategoryIndex=1,numSubCatgories do
  18.       local _, numAchievements = GetAchievementSubCategoryInfo(topLevelIndex, subCategoryIndex)
  19.       GetAchievements(topLevelIndex, subCategoryIndex, numAchievements)
  20.     end
  21.   end
  22. end
But you can probe the ids with local name = GetAchievementInfo(id) until name is nil.

Originally Posted by hisdad View Post
Thx Votan,
It works with the problem that no matter how many I want (9999) it returns a max of 10.
Is there a better way of doing this?

--Dad
  Reply With Quote
04/02/15, 02:30 PM   #5
hisdad
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 33
Originally Posted by votan View Post
That's using offical API functions:
Lua Code:
  1. local function GetAll()
  2.   local function GetAchievements(topLevelIndex, categoryIndex, numAchievements)
  3.     for achievementIndex=1,numAchievements do
  4.       local achievementId = GetAchievementId(topLevelIndex, categoryIndex, achievementIndex)
  5.       local _, _, _, _, completed = GetAchievementInfo(achievementId)
  6.       while achievementId ~= 0 do
  7.         d(achievementId)
  8.         achievementId = GetNextAchievementInLine(achievementId)
  9.       end
  10.     end
  11.   end
  12.  
  13.   local numCategories = GetNumAchievementCategories()
  14.   for topLevelIndex=1,numCategories do
  15.     local _, numSubCatgories, numAchievements = GetAchievementCategoryInfo(topLevelIndex)
  16.     GetAchievements(topLevelIndex, nil, numAchievements) -- General
  17.     for subCategoryIndex=1,numSubCatgories do
  18.       local _, numAchievements = GetAchievementSubCategoryInfo(topLevelIndex, subCategoryIndex)
  19.       GetAchievements(topLevelIndex, subCategoryIndex, numAchievements)
  20.     end
  21.   end
  22. end
But you can probe the ids with local name = GetAchievementInfo(id) until name is nil.
Heh! I was wondering about that. But that categories code is good since I want to capture that info anyway.
Rather than starting with ID's and working back I'll do as you suggest and work forward.

Thx V Much

--Dad
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » GetRecentlyCompletedAchievements() Advice on returns


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off