post again.... :)

hi… i made a game by using gamenetwork to connect to game play android… but everytime i press the leader button or achievement button . its always closed the game n show up  ” unfortunately, project has stopped" ( project is my app name")…  anyone can help wut is wrong with the code… will be very thankful…

here is my code …

  1. – json = require(“json”)                          – used for file i/o
  2. lime = require(“lime”)                          – used for top 10 list manipulation
  3. local gameNetwork = require( “gameNetwork” )    – Google Play network
  4.  
  5. – Google Play Games leaderboard and achievements are referenced by ID’s. After defining these
  6. – on the Google Play Developer Console (http://play.google.com/apps/publish) , update them here
  7. local gpgLeaderBoardID = “CgkI8J_r9sMXXXXX”           – id for leaderboard (you can have several) 
  8. local gpgAchieve1ID = “CgkI8J_r9sXXXXXXX”           – id for perfect level 1 achievement
  9. local gpgAchieve2ID = “CgkI8J_r9sMXXXXXX”           – id for perfect level 2 achievement
  10. local gpgAchieve3ID = “CgkI8J_r9sMYXXXXX”           – id for perfect level 3 achievement
  11. local gpgAchieve4ID = “ACHIEVEMENT ID #4”           – id for perfect level 4 achievement
  12. local gpgAchieve5ID = “ACHIEVEMENT ID #5”  
  13.  
  14.  
  15. – Top 10 scores variables
  16. local topRank = {}                              – rank 1-10
  17. local topScore = {}                             – score
  18. local topName = {}                              – player’s name
  19. local topDate = {}                              – date score was recorded
  20.  
  21.  
  22. local function adListener( event )
  23. end
  24.  
  25. – Google Play Games has fetched the current player’s data.  
  26. local function loadLocalPlayerCallback( event )
  27.     – Let’s remember the player’s name for high score pre-loading
  28.    playerName = event.data.alias
  29. end
  30.  
  31. – Google Play Games network login events
  32. local function gameNetworkLoginCallback( event )
  33.     – request player data
  34.    gameNetwork.request( “loadLocalPlayer”, { listener=loadLocalPlayerCallback } )
  35.    return true
  36. end
  37.  
  38. – Google Play Games login initialize events
  39. local function gpgsInitCallback( event )
  40.     – request a login
  41.    gameNetwork.request( “login”, { userInitiated=true, listener=gameNetworkLoginCallback } )
  42. end
  43.  
  44. – process user prompt to login to Google Play Game services
  45. local function onClickGpLogin( event )
  46.     if “clicked” == event.action then
  47.         local i = event.index
  48.         – when i = 1, user is confirming a login prompt.
  49.         if i == 1 then gpgsInitCallback(nil) end
  50.     end
  51. end]
  52.  
  53. function setUpIntroScreen(myInt)
  54.  
  55.  
  56.     introScreenGroup = display.newGroup()             
  57.  
  58.     – position all of our graphics on the screen
  59.     local titleScreen = display.newImage(“main.jpg”,display.contentCenterX,display.contentCenterY)
  60.     local playButton = display.newImage(“start.png”,482,210)        – play button   
  61.     local helpButton = display.newImage(“rules.png”,615,210)        – rules/help button
  62.     local leaderButton = display.newImage(“leader.png”,433,340)     – Google Play Leaderboard button
  63.     local achieveButton = display.newImage(“achieve.png”,570,340)   – Google Play achievement button
  64.     local scoreButton = display.newImage(“scores.png”,705,340)      – local scores button
  65.  
  66.  
  67.     introScreenGroup:insert(leaderButton)
  68.     introScreenGroup:insert(achieveButton)
  69.  
  70.     – define what happens when the leaderboard button is tapped.
  71.     leaderButton:addEventListener(“tap”,function ()
  72.             if (gameNetwork.request(“isConnected”)) then                – has the user connected to Google Play Games?
  73. print (“ayo main”)
  74.                    audio.play(soundEnemy4, {onComplete = function ()    – play a sound and when it’s done
  75.                         gameNetwork.show( “leaderboards”  )             – display the leaderboard
  76.                     end})
  77.             else
  78.                 – the user has not linked their account to the game, give them the option to do so. 
  79.                 native.showAlert (“Google+ required”, “You have not connected your Google+ account to this app”
  80.                     , {“Connect Now”, “Cancel”}, onClickGpLogin)
  81.             end
  82.     end)
  83.  
  84.     – define what happens when the achievement button is tapped.
  85.     achieveButton:addEventListener(“tap”,function ()                    
  86.             if (gameNetwork.request(“isConnected”)) then                – has the user connected to Google Play Games?
  87.                 audio.play(soundEnemy3, {onComplete = function ()       – play a sound and when it’s done
  88.                         gameNetwork.show( “achievements”  )             – display the achievements
  89.                     end})
  90.             else
  91.                 – the user has not linked their account to the game, give them the option to do so. 
  92.                 native.showAlert (“Google+ required”, “You have not connected your Google+ account to this app”
  93.                     , {“Connect Now”, “Cancel”}, onClickGpLogin)
  94.             end
  95.     end)
  96. end
  97.  
  98. function alert(myInt)
  99.  
  100.  if (gameNetwork.request(“isConnected”)) then                – is player connected to Google Play ?
  101.             if (points > highScore) then                            – did player beat this session’s highest score?
  102.                 – update leaderboard. ‘category’ = your Google Play leaderboard id
  103.                 gameNetwork.request( “setHighScore”, {localPlayerScore={ category=gpgLeaderBoardID, value=tonumber(points)}})                           – 
  104.                 highScore = points                                  – this will prevent future lower scores from wasting their
  105.             end                                                     – attempting to update leaderboard
  106.  
  107.             – achievement checking. each request identifier = your Google Play achievement id
  108.             – the achievedReached array tracks each unlocked achievemnt to prevent unlocking an achievement
  109.             – which has already been unlocked in this session.
  110.             if (achieveReached[1] == 0) and (perfectLevels[1]==1) then          – perfect level 1?
  111.                 achieveReached[1] = 1
  112.                 gameNetwork.request( “unlockAchievement”,                       – request an achievement unlock
  113.                     {achievement = { identifier=gpgAchieve1ID,                  – id for perfect level 1 achievement
  114.                     percentComplete=100, showsCompletionBanner=true }} )
  115.             end
  116.             if (achieveReached[2] == 0) and (perfectLevels[2]==1) then          – perfect level 2?
  117.                 achieveReached[2] = 1
  118.                 gameNetwork.request( “unlockAchievement”,                       – request an achievement unlock
  119.                     {achievement = { identifier=gpgAchieve2ID,                  – id for perfect level 2 achievement
  120.                     percentComplete=100, showsCompletionBanner=true }} )
  121.             end
  122.             if (achieveReached[3] == 0) and (perfectLevels[3]==1) then          – perfect level 3?            
  123.                 achieveReached[3] = 1
  124.                 gameNetwork.request( “unlockAchievement”,                       – request an achievement unlock
  125.                     {achievement = { identifier=gpgAchieve3ID,                  – id for perfect level 3 achievement
  126.                     percentComplete=100, showsCompletionBanner=true }} )
  127.             end
  128.             if (achieveReached[4] == 0) and (perfectLevels[4]==1) then          – perfect level 4?
  129.                 achieveReached[4] = 1
  130.                 gameNetwork.request( “unlockAchievement”,                       – request an achievement unlock
  131.                     {achievement = { identifier=gpgAchieve4ID,                  – id for perfect level 4 achievement
  132.                     percentComplete=100, showsCompletionBanner=true }} )
  133.             end
  134.             if (achieveReached[5] == 0) and (points>=700) then                  – exceeded 700 points?
  135.                 achieveReached[5] = 1                                           
  136.                 gameNetwork.request( “unlockAchievement”,                       – request an achievement unlock
  137.                     {achievement = { identifier=gpgAchieve5ID,                  – id for exceeded threshold achievement
  138.                     percentComplete=100, showsCompletionBanner=true }} )
  139.             end
  140.         end
  141. end
  142.  
  143. gameNetwork.init( “google”, gpgsInitCallback)

 

everything good… just only leaderboard n achievement… when i pressed it, it always closed the game …

here is my build.settings

 

 

  1. – -- Supported values for orientation:
  2. – portrait, portraitUpsideDown, landscapeLeft, landscapeRight
  3.  
  4. settings = {
  5.  
  6. orientation = {
  7. default = “landscapeRight”,
  8. supported = { “landscapeRight”, }
  9. },
  10. plugins =    {
  11.         – key is the name passed to Lua’s ‘require()’
  12.         [“plugin.google.play.services”] =
  13.         {
  14.             – required
  15.             publisherId = “com.coronalabs”,
  16.         },
  17.  
  18.         [“CoronaProvider.gameNetwork.google”] =
  19.         {
  20.             --required!
  21.             publisherId = “com.coronalabs”,
  22.         },
  23.         [“facebook”] =
  24.         {
  25.             publisherId = “com.coronalabs”
  26.         },
  27.     }, 
  28. iphone = {
  29. plist = {
  30. UIStatusBarHidden = false,
  31. UIPrerenderedIcon = true, – set to false for “shine” overlay
  32. –UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend
  33.  
  34.             --[[
  35.             – iOS app URL schemes:
  36.             CFBundleURLTypes =
  37.             {
  38.                 {
  39.                     CFBundleURLSchemes =
  40.                     {
  41.                         “fbXXXXXXXXXXXXXX”, – example scheme for facebook
  42.                         “coronasdkapp”, – example second scheme
  43.                     }
  44.                 }
  45.             }
  46.             --]]
  47. }
  48. },
  49.  
  50. –[[
  51. – Android permissions
  52.  
  53. androidPermissions = {
  54.   “android.permission.INTERNET”,
  55.   },
  56.  
  57. ]]–
  58.  
  59. android = {
  60.         googlePlayGamesAppId = “84286811XXX”  --long App ID number (use yours!)
  61.     },
  62. }

You need to find out what the actual error message is before anyone can help. As this is Android, you need to connect your device to your computer using ADB or Android Monitor, and look for error messages related to your app.

I would add more print statements throughout the code as well, to make it easier to see which step it fails on. You have one print that says “ayo main”. Do you see that printed anywhere? I would also add one to the audio.play onComplete function at the very least, for all you know it could be the audio failing to play that’s causing the error rather than the game network calls.

here is my build.settings

 

 

  1. – -- Supported values for orientation:
  2. – portrait, portraitUpsideDown, landscapeLeft, landscapeRight
  3.  
  4. settings = {
  5.  
  6. orientation = {
  7. default = “landscapeRight”,
  8. supported = { “landscapeRight”, }
  9. },
  10. plugins =    {
  11.         – key is the name passed to Lua’s ‘require()’
  12.         [“plugin.google.play.services”] =
  13.         {
  14.             – required
  15.             publisherId = “com.coronalabs”,
  16.         },
  17.  
  18.         [“CoronaProvider.gameNetwork.google”] =
  19.         {
  20.             --required!
  21.             publisherId = “com.coronalabs”,
  22.         },
  23.         [“facebook”] =
  24.         {
  25.             publisherId = “com.coronalabs”
  26.         },
  27.     }, 
  28. iphone = {
  29. plist = {
  30. UIStatusBarHidden = false,
  31. UIPrerenderedIcon = true, – set to false for “shine” overlay
  32. –UIApplicationExitsOnSuspend = true, – uncomment to quit app on suspend
  33.  
  34.             --[[
  35.             – iOS app URL schemes:
  36.             CFBundleURLTypes =
  37.             {
  38.                 {
  39.                     CFBundleURLSchemes =
  40.                     {
  41.                         “fbXXXXXXXXXXXXXX”, – example scheme for facebook
  42.                         “coronasdkapp”, – example second scheme
  43.                     }
  44.                 }
  45.             }
  46.             --]]
  47. }
  48. },
  49.  
  50. –[[
  51. – Android permissions
  52.  
  53. androidPermissions = {
  54.   “android.permission.INTERNET”,
  55.   },
  56.  
  57. ]]–
  58.  
  59. android = {
  60.         googlePlayGamesAppId = “84286811XXX”  --long App ID number (use yours!)
  61.     },
  62. }

You need to find out what the actual error message is before anyone can help. As this is Android, you need to connect your device to your computer using ADB or Android Monitor, and look for error messages related to your app.

I would add more print statements throughout the code as well, to make it easier to see which step it fails on. You have one print that says “ayo main”. Do you see that printed anywhere? I would also add one to the audio.play onComplete function at the very least, for all you know it could be the audio failing to play that’s causing the error rather than the game network calls.