Setting up game centre acheivements help

Im a little confused at how this works and cannot find a single tutorial which explains how to get unlocked achievements to work in corona sdk. I have the achievements setup on iTunes and have put in the following code in my GameOver function:

if loggedIntoGC then local message if miles == 5 then gameNetwork.request( "unlockAchievement", { achievement = { identifier = "a\_1", -- Achievement Id in iTunes percentComplete = 100, showsCompletionBanner = true, }, }) end end

When loading up Game Center on device I can see the achievements are there and ready to be unlocked, but nothing happens when I meet its conditions. The code above was taken from the sample code inside the corona folder. Can someone please provide assistance because I do not understand what to do. Cheers

Did you init Game Center in main.lua?  Check out this page for details.

Also, if you are testing this prior to release, you need to enable sandbox mode.

My game center init is actually in a separate file called Scoring.lua which I require on all scenes. 

local function onSystemEvent( event ) if event.type == "applicationStart" or event.type == "applicationResume" then if utils.platform == "Android" then gameNetwork.init( "google", initCallback ) else gameNetwork.init( "gamecenter", initCallback ) end return true end end Runtime:addEventListener( "system", onSystemEvent ) onSystemEvent( {type="applicationStart"} ) 

Should My OP code be in the scoring.lua file with the game center code? 

I believe the preferred method is to place this init code in main.lua since (for Apple), the init needs to occur when the application starts or resumes. 

A solution that I implemented was to create a game center library that handles Apple, Google, and Amazon, including init code.   I called the init code in my library within the onSystemEvent function located in main.lua.

Hope this helps.

The “loggedIntoGC” value is local to scoring.lua, therefore trying to use it from game.lua won’t work. 

You’ll need to either get rid of that line of code in your gameOver function so it always tries to do it, or create a new unlockAchievement function in scoring.lua that you can call from game.lua. E.g “scoring.unlockAchievement( achievement_id )”. If I have time later I’ll send you a different scoring.lua file that also deals with achievements. 

Thanks for the reply, that would be great if you could send me that file.

Did you init Game Center in main.lua?  Check out this page for details.

Also, if you are testing this prior to release, you need to enable sandbox mode.

My game center init is actually in a separate file called Scoring.lua which I require on all scenes. 

local function onSystemEvent( event ) if event.type == "applicationStart" or event.type == "applicationResume" then if utils.platform == "Android" then gameNetwork.init( "google", initCallback ) else gameNetwork.init( "gamecenter", initCallback ) end return true end end Runtime:addEventListener( "system", onSystemEvent ) onSystemEvent( {type="applicationStart"} ) 

Should My OP code be in the scoring.lua file with the game center code? 

I believe the preferred method is to place this init code in main.lua since (for Apple), the init needs to occur when the application starts or resumes. 

A solution that I implemented was to create a game center library that handles Apple, Google, and Amazon, including init code.   I called the init code in my library within the onSystemEvent function located in main.lua.

Hope this helps.

The “loggedIntoGC” value is local to scoring.lua, therefore trying to use it from game.lua won’t work. 

You’ll need to either get rid of that line of code in your gameOver function so it always tries to do it, or create a new unlockAchievement function in scoring.lua that you can call from game.lua. E.g “scoring.unlockAchievement( achievement_id )”. If I have time later I’ll send you a different scoring.lua file that also deals with achievements. 

Thanks for the reply, that would be great if you could send me that file.