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 …
[lua]-- 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”)
audio.play(soundEnemy4, {onComplete = function () – play a sound and when it’s done
gameNetwork.show( “leaderboards” ) – display the leaderboard
end})
else
– 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 – 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
– 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)
end
function alert(myInt)
if (gameNetwork.request(“isConnected”)) then – is player connected to Google Play ?
if (points > highScore) then – did player beat this session’s highest score?
– update leaderboard. ‘category’ = your Google Play leaderboard id
gameNetwork.request( “setHighScore”, {localPlayerScore={ category=gpgLeaderBoardID, value=tonumber(points)}}) –
highScore = points – this will prevent future lower scores from wasting their
end – attempting to update leaderboard
– achievement checking. each request identifier = your Google Play achievement id
– the achievedReached array tracks each unlocked achievemnt to prevent unlocking an achievement
– which has already been unlocked in this session.
if (achieveReached[1] == 0) and (perfectLevels[1]==1) then – perfect level 1?
achieveReached[1] = 1
gameNetwork.request( “unlockAchievement”, – request an achievement unlock
{achievement = { identifier=gpgAchieve1ID, – id for perfect level 1 achievement
percentComplete=100, showsCompletionBanner=true }} )
end
if (achieveReached[2] == 0) and (perfectLevels[2]==1) then – perfect level 2?
achieveReached[2] = 1
gameNetwork.request( “unlockAchievement”, – request an achievement unlock
{achievement = { identifier=gpgAchieve2ID, – id for perfect level 2 achievement
percentComplete=100, showsCompletionBanner=true }} )
end
if (achieveReached[3] == 0) and (perfectLevels[3]==1) then – perfect level 3?
achieveReached[3] = 1
gameNetwork.request( “unlockAchievement”, – request an achievement unlock
{achievement = { identifier=gpgAchieve3ID, – id for perfect level 3 achievement
percentComplete=100, showsCompletionBanner=true }} )
end
if (achieveReached[4] == 0) and (perfectLevels[4]==1) then – perfect level 4?
achieveReached[4] = 1
gameNetwork.request( “unlockAchievement”, – request an achievement unlock
{achievement = { identifier=gpgAchieve4ID, – id for perfect level 4 achievement
percentComplete=100, showsCompletionBanner=true }} )
end
if (achieveReached[5] == 0) and (points>=700) then – exceeded 700 points?
achieveReached[5] = 1
gameNetwork.request( “unlockAchievement”, – request an achievement unlock
{achievement = { identifier=gpgAchieve5ID, – id for exceeded threshold achievement
percentComplete=100, showsCompletionBanner=true }} )
end
end
end
gameNetwork.init( “google”, gpgsInitCallback) [/lua]
everything good… just only leaderboard n achievement… when i pressed it, it always closed the game …