How do you use the gameNetwork loadAchievements() function?

Hi there!

How do you make sure that you submit an achievement only once? And with regards to this, may I ask for an example return value of “loadAchievements”?

Yet another question, in the code below:

[lua]gameNetwork.request( “unlockAchievement”,
{
achievement =
{
identifier = achievementID,
percentComplete = 100,
showsCompletionBanner = true,
},
listener = requestCallback
})[/lua]

What should the requestCallback contain/do?

Thanks for the help!

Regards,

John [import]uid: 186198 topic_id: 33015 reply_id: 333015[/import]

So I made some code to detect if a certain achievement has been completed, but it still keeps on unlocking the achievement, need some help please?

[lua]local achievementId_to_check = “”

– check the achievements
local function requestCallback( event )
if event.type == “loadAchievements” then
if event.data then
for i,v in pairs(event.data) do
if (event.data[i].identifier == achievementID) then
achievementId_to_check = “”
return true – achievement done!
end
end
achievementId_to_check = “”
return false – achievement done!
end
end
end
function check_achievement( achievementID )
– check if iOS device and connection is active
achievementId_to_check = achievementID
return gameNetwork.request( “loadAchievements”, { listener=requestCallback } )
end

function unlockAchievement( achievementID )
– check if iOS device and connection is active
if (model == “iPad” or model == “iPhone” or model == “iPod touch”) and testNetworkConnection() and loggedIntoGC then
– check if achievement is complete
if (check_achievement(achievementID)) then
else
gameNetwork.request( “unlockAchievement”,
{
achievement =
{
identifier = achievementID,
percentComplete = 100,
showsCompletionBanner = true,
},
listener = requestCallback
})
end
end
end[/lua]

usage:

[lua]unlockAchievement(“complete6x6board002”)[/lua] [import]uid: 186198 topic_id: 33015 reply_id: 131062[/import]

So I made some code to detect if a certain achievement has been completed, but it still keeps on unlocking the achievement, need some help please?

[lua]local achievementId_to_check = “”

– check the achievements
local function requestCallback( event )
if event.type == “loadAchievements” then
if event.data then
for i,v in pairs(event.data) do
if (event.data[i].identifier == achievementID) then
achievementId_to_check = “”
return true – achievement done!
end
end
achievementId_to_check = “”
return false – achievement done!
end
end
end
function check_achievement( achievementID )
– check if iOS device and connection is active
achievementId_to_check = achievementID
return gameNetwork.request( “loadAchievements”, { listener=requestCallback } )
end

function unlockAchievement( achievementID )
– check if iOS device and connection is active
if (model == “iPad” or model == “iPhone” or model == “iPod touch”) and testNetworkConnection() and loggedIntoGC then
– check if achievement is complete
if (check_achievement(achievementID)) then
else
gameNetwork.request( “unlockAchievement”,
{
achievement =
{
identifier = achievementID,
percentComplete = 100,
showsCompletionBanner = true,
},
listener = requestCallback
})
end
end
end[/lua]

usage:

[lua]unlockAchievement(“complete6x6board002”)[/lua] [import]uid: 186198 topic_id: 33015 reply_id: 131062[/import]

I haven’t played with this but it appears you want to set show banner to false - read info here; http://developer.coronalabs.com/reference/index/game-network/gamenetworkrequest (About a third of the way down the page.)

Leaving/setting it as true should keep showing the banner each time. [import]uid: 52491 topic_id: 33015 reply_id: 131165[/import]

Hi Peach!

No, I’m not trying to hide the banner, I’m trying to check if a specific achievement has been completed. If it has not been completed yet, then send a request to achieve it.

hiding the banner may be a solution, but it’s not a very optimal one.:frowning:

Regards,

John [import]uid: 186198 topic_id: 33015 reply_id: 131167[/import]

I haven’t played with this but it appears you want to set show banner to false - read info here; http://developer.coronalabs.com/reference/index/game-network/gamenetworkrequest (About a third of the way down the page.)

Leaving/setting it as true should keep showing the banner each time. [import]uid: 52491 topic_id: 33015 reply_id: 131165[/import]

Hi Peach!

No, I’m not trying to hide the banner, I’m trying to check if a specific achievement has been completed. If it has not been completed yet, then send a request to achieve it.

hiding the banner may be a solution, but it’s not a very optimal one.:frowning:

Regards,

John [import]uid: 186198 topic_id: 33015 reply_id: 131167[/import]

No other replies yet? :frowning: Please help me, :frowning:

Regards,

John [import]uid: 186198 topic_id: 33015 reply_id: 131469[/import]

No other replies yet? :frowning: Please help me, :frowning:

Regards,

John [import]uid: 186198 topic_id: 33015 reply_id: 131469[/import]

Can you not load achievements, run through array and set a flag to only unlock if not already unlocked? I haven’t done much with GameCenter due to testing requirements but this seems like the process you’d want to use if you didn’t want to simply not display it being re-achieved. [import]uid: 52491 topic_id: 33015 reply_id: 131629[/import]

Can you not load achievements, run through array and set a flag to only unlock if not already unlocked? I haven’t done much with GameCenter due to testing requirements but this seems like the process you’d want to use if you didn’t want to simply not display it being re-achieved. [import]uid: 52491 topic_id: 33015 reply_id: 131629[/import]