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 …
- – json = require(“json”) – used for file i/o
- lime = require(“lime”) – used for top 10 list manipulation
- local gameNetwork = require( “gameNetwork” ) – Google Play network
- – Google Play Games leaderboard and achievements are referenced by ID’s. After defining these
- – on the Google Play Developer Console (http://play.google.com/apps/publish) , update them here
- local gpgLeaderBoardID = “CgkI8J_r9sMXXXXX” – id for leaderboard (you can have several)
- local gpgAchieve1ID = “CgkI8J_r9sXXXXXXX” – id for perfect level 1 achievement
- local gpgAchieve2ID = “CgkI8J_r9sMXXXXXX” – id for perfect level 2 achievement
- local gpgAchieve3ID = “CgkI8J_r9sMYXXXXX” – id for perfect level 3 achievement
- local gpgAchieve4ID = “ACHIEVEMENT ID #4” – id for perfect level 4 achievement
- local gpgAchieve5ID = “ACHIEVEMENT ID #5”
- – Top 10 scores variables
- local topRank = {} – rank 1-10
- local topScore = {} – score
- local topName = {} – player’s name
- local topDate = {} – date score was recorded
- local function adListener( event )
- end
- – Google Play Games has fetched the current player’s data.
- local function loadLocalPlayerCallback( event )
- – Let’s remember the player’s name for high score pre-loading
- playerName = event.data.alias
- end
- – Google Play Games network login events
- local function gameNetworkLoginCallback( event )
- – request player data
- gameNetwork.request( “loadLocalPlayer”, { listener=loadLocalPlayerCallback } )
- return true
- end
- – Google Play Games login initialize events
- local function gpgsInitCallback( event )
- – request a login
- gameNetwork.request( “login”, { userInitiated=true, listener=gameNetworkLoginCallback } )
- end
- – process user prompt to login to Google Play Game services
- local function onClickGpLogin( event )
- if “clicked” == event.action then
- local i = event.index
- – when i = 1, user is confirming a login prompt.
- if i == 1 then gpgsInitCallback(nil) end
- end
- end]
- function setUpIntroScreen(myInt)
- introScreenGroup = display.newGroup()
- – position all of our graphics on the screen
- local titleScreen = display.newImage(“main.jpg”,display.contentCenterX,display.contentCenterY)
- local playButton = display.newImage(“start.png”,482,210) – play button
- local helpButton = display.newImage(“rules.png”,615,210) – rules/help button
- local leaderButton = display.newImage(“leader.png”,433,340) – Google Play Leaderboard button
- local achieveButton = display.newImage(“achieve.png”,570,340) – Google Play achievement button
- local scoreButton = display.newImage(“scores.png”,705,340) – local scores button
- introScreenGroup:insert(leaderButton)
- introScreenGroup:insert(achieveButton)
- – define what happens when the leaderboard button is tapped.
leaderButton:addEventListener(“tap”,function ()
if (gameNetwork.request(“isConnected”)) then – has the user connected to Google Play Games?
print (“ayo main L”)
audio.play(soundEnemy4, {onComplete = function () – play a sound and when it’s done
gameNetwork.show( “leaderboards” ) – display the leaderboard
end})
else
print (“kenapa L”)
– the user has not linked their account to the game, give them the option to do so.
native.showAlert (“Google+ required”, “You have not connected your Google+ account to this app”
, {“Connect Now”, “Cancel”}, onClickGpLogin)
end
end)
– define what happens when the achievement button is tapped.
achieveButton:addEventListener(“tap”,function ()
if (gameNetwork.request(“isConnected”)) then
print (“ayo main”)-- has the user connected to Google Play Games?
audio.play(soundEnemy3, {onComplete = function () – play a sound and when it’s done
gameNetwork.show( “achievements” ) – display the achievements
end})
else
print (“kenapa?”)
– the user has not linked their account to the game, give them the option to do so.
native.showAlert (“Google+ required”, “You have not connected your Google+ account to this app”
, {“Connect Now”, “Cancel”}, onClickGpLogin)
end
72. end)
73. end
74.
75. function alert(myInt)
76.
77. if (gameNetwork.request(“isConnected”)) then – is player connected to Google Play ?
78. if (points > highScore) then – did player beat this session’s highest score?
79. – update leaderboard. ‘category’ = your Google Play leaderboard id
80. gameNetwork.request( “setHighScore”, {localPlayerScore={ category=gpgLeaderBoardID,value=tonumber(points)}}) –
81. highScore = points – this will prevent future lower scores from wasting their
82. end – attempting to update leaderboard
83.
84. – achievement checking. each request identifier = your Google Play achievement id
85. – the achievedReached array tracks each unlocked achievemnt to prevent unlocking an achievement
86. – which has already been unlocked in this session.
87. if (achieveReached[1] == 0) and (perfectLevels[1]==1) then – perfect level 1?
88. achieveReached[1] = 1
89. gameNetwork.request( “unlockAchievement”, – request an achievement unlock
90. {achievement = { identifier=gpgAchieve1ID, – id for perfect level 1 achievement
91. percentComplete=100, showsCompletionBanner=true }} )
92. end
93. if (achieveReached[2] == 0) and (perfectLevels[2]==1) then – perfect level 2?
94. achieveReached[2] = 1
95. gameNetwork.request( “unlockAchievement”, – request an achievement unlock
96. {achievement = { identifier=gpgAchieve2ID, – id for perfect level 2 achievement
97. percentComplete=100, showsCompletionBanner=true }} )
98. end
99. if (achieveReached[3] == 0) and (perfectLevels[3]==1) then – perfect level 3?
100. achieveReached[3] = 1
101. gameNetwork.request( “unlockAchievement”, – request an achievement unlock
102. {achievement = { identifier=gpgAchieve3ID, – id for perfect level 3 achievement
103. percentComplete=100, showsCompletionBanner=true }} )
104. end
105. if (achieveReached[4] == 0) and (perfectLevels[4]==1) then – perfect level 4?
106. achieveReached[4] = 1
107. gameNetwork.request( “unlockAchievement”, – request an achievement unlock
108. {achievement = { identifier=gpgAchieve4ID, – id for perfect level 4 achievement
109. percentComplete=100, showsCompletionBanner=true }} )
110. end
111. if (achieveReached[5] == 0) and (points>=700) then – exceeded 700 points?
112. achieveReached[5] = 1
113. gameNetwork.request( “unlockAchievement”, – request an achievement unlock
114. {achievement = { identifier=gpgAchieve5ID, – id for exceeded threshold achievement
115. percentComplete=100, showsCompletionBanner=true }} )
116. end
117. end
118. end
119.
120. gameNetwork.init( “google”, gpgsInitCallback)
everything good… just only leaderboard n achievement… when i pressed it, it always closed the game …