force stop after adding GPGS to the game

Hi,

here’s my main.lua code :

[lua]local centerX = display.contentCenterX
local centerY = display.contentCenterY
local _W = display.contentWidth
local _H = display.contentHeight
local gameNetwork = require “gameNetwork”
gameNetwork.init(“google”)

local leaderboardId = “” – Your leaderboard id here

gameNetwork.request(“login”,{userInitiated = true})

local function submitScoreListener(event)
gameNetwork.request(“setHighScore”,
{
localPlayerScore =
{
category = leaderboardId, – Id of the leaderboard to submit the score into
value = 100 – The score to submit
}
})
end

local function showLeaderboardListener(event)
gameNetwork.show(“leaderboards”) – Shows all the leaderboards.
end


local storyboard = require (“storyboard”)

local btn = display.newText(“play1”, 0, 0, nil, 50)
btn.x=_W/2; btn.y=_H/2 - 30;

local btn2 = display.newText(“leaderboards”, 0, 0, nil, 50)
btn2.x=_W/2; btn2.y=_H/2+20;

local btn3 = display.newText(“submit”, 0, 0, nil, 50)
btn3.x=_W/2; btn3.y=_H/2+60;

function tbtn(e)
if e.phase == “ended” then
btn:removeSelf()
storyboard.gotoScene(“game2”)
end
end

function tbtn2(e)
if e.phase == “ended” then
showLeaderboardListener()
end
end

function tbtn3(e)
if e.phase == “ended” then
submitScoreListener()
end
end

btn:addEventListener(“touch”, tbtn)
btn2:addEventListener(“touch”, tbtn2)
btn3:addEventListener(“touch”, tbtn3)[/lua]

but after building the game and trying to open it on device, the app stops and shows a pupup saying :

unfortunately, application has stopped.

Are there any messages in your device’s console log?

there are only warnings saying : the game network provider <google> not available on the simulator. and another saying the library not available on this platform.

You can only test GPGS on a device.  Your app in the simulator should not stop because of this.  Can you copy/paste the exact messages you are getting?  Post your build.settings as well.

Rob

yes, I’m talking about testing on my device, the app works fine in simulator.

build.settings :

[lua]settings = {
android = {
googlePlayGamesAppId = " 42229938906",
versionCode = “1”,
usesPermissions =
{
“android.permission.INTERNET”,
“android.permission.ACCESS_NETWORK_STATE”,
},
},
plugins = {
–[“CoronaProvider.ads.admob”] = { publisherId = “com.coronalabs” },
[“CoronaProvider.gameNetwork.google”] = { publisherId = “com.coronalabs”, supportedPlatforms = { android = true } },
},
orientation = {
default = “portrait”,
supported = { “portrait”, }
},[/lua]

messages :

warning :  the game network provider <google> not available on the simulator

warning :  the game network library not available on this platform

What device are you building for?

I’m building for android (galaxy note 3)

If that’s your complete build.settings you’re missing a closing } at the end.

Rob

Also see this line:  googlePlayGamesAppId = " 42229938906",

There is a space between the " and the 4 that probably shouldn’t be there.

I fixed that and now the app doesn’t crash, but leaderboard does’t show ! and there’s no logging-in

I would suggest reading this tutorial:  http://coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/

You’re missing setting up a call back listener in your .init() call so your login call has no place to return to so it can continue.

Rob

I came with this after the tutorial :

[lua]local gameNetwork = require “gameNetwork”
local leaderboardId = “CgkI2vXmqJ0BEAIQAA”
local playerName

local function loadLocalPlayerCallback( event )
playerName = event.data.alias
end

local function gameNetworkLoginCallback( event )
gameNetwork.request( “loadLocalPlayer”, { listener=loadLocalPlayerCallback } )
return true
end

local function gpgsInitCallback( event )
gameNetwork.request( “login”, { userInitiated=true, listener=gameNetworkLoginCallback } )
end

gameNetwork.init(“google”, gpgsInitCallback)

function scoreSubmit()
print(“SSUBMIT”)
end

local function submitScoreListener()
scoreSubmit()
gameNetwork.request(“setHighScore”, {localPlayerScore = {category = leaderboardId, value = 100}})
end


local storyboard = require (“storyboard”)

local btn = display.newText(“play1”, 0, 0, nil, 50)
btn.x=_W/2; btn.y=_H/2 - 30;

local btn2 = display.newText(“leaderboards”, 0, 0, nil, 50)
btn2.x=_W/2; btn2.y=_H/2+20;

local btn3 = display.newText(“submit”, 0, 0, nil, 50)
btn3.x=_W/2; btn3.y=_H/2+60;

function tbtn(e)
if e.phase == “ended” then
btn:removeSelf()
storyboard.gotoScene(“game2”)
end
end

function tbtn2(e)
if e.phase == “ended” then
gameNetwork.show(“leaderboards”)
end
end

function tbtn3(e)
if e.phase == “ended” then
submitScoreListener()
end
end

btn:addEventListener(“touch”, tbtn)
btn2:addEventListener(“touch”, tbtn2)
btn3:addEventListener(“touch”, tbtn3)[/lua]

is this how it sould be ?

I came with this after the tutorial :

[lua]local gameNetwork = require “gameNetwork”
local leaderboardId = “CgkI2vXmqJ0BEAIQAA”
local playerName

local function loadLocalPlayerCallback( event )
playerName = event.data.alias
end

local function gameNetworkLoginCallback( event )
gameNetwork.request( “loadLocalPlayer”, { listener=loadLocalPlayerCallback } )
return true
end

local function gpgsInitCallback( event )
gameNetwork.request( “login”, { userInitiated=true, listener=gameNetworkLoginCallback } )
end

gameNetwork.init(“google”, gpgsInitCallback)

function scoreSubmit()
print(“SSUBMIT”)
end

local function submitScoreListener()
scoreSubmit()
gameNetwork.request(“setHighScore”, {localPlayerScore = {category = leaderboardId, value = 100}})
end


local storyboard = require (“storyboard”)

local btn = display.newText(“play1”, 0, 0, nil, 50)
btn.x=_W/2; btn.y=_H/2 - 30;

local btn2 = display.newText(“leaderboards”, 0, 0, nil, 50)
btn2.x=_W/2; btn2.y=_H/2+20;

local btn3 = display.newText(“submit”, 0, 0, nil, 50)
btn3.x=_W/2; btn3.y=_H/2+60;

function tbtn(e)
if e.phase == “ended” then
btn:removeSelf()
storyboard.gotoScene(“game2”)
end
end

function tbtn2(e)
if e.phase == “ended” then
gameNetwork.show(“leaderboards”)
end
end

function tbtn3(e)
if e.phase == “ended” then
submitScoreListener()
end
end

btn:addEventListener(“touch”, tbtn)
btn2:addEventListener(“touch”, tbtn2)
btn3:addEventListener(“touch”, tbtn3)[/lua]

is this how it sould be ?

That’s closer.  It’s really hard to read without the indents.  But it looks like you’re calling gameNetwork.init() with a call back so it should start the chain reaction of the login process.  You can put in some print statements to make sure you’re getting to where you need to go.

Rob

I got it to log-in but the leaderboard doesn’t show up !

would you mind taking a look on the main.lua 

here

When you run your app, do you actually see a Google Play login screen pop up?  Does it ask you for the account to login to?  Do you see a “Welcome back” popup at the top of the screen?

Your code basically works, but you may have setup issues on Google play.  Did you take that space out of your AppID in your build.settings?

Rob

yes, there’s a pop up login and asking for login, but there’s NO welcome back .

yes I fixed the space in the build.setting 

could it be a problem if the package name was different from the in google play console ?

The package name must match what you setup in google play

I matched but still leader board doesn’t show, should I set the targeted store to google play ? should I upload the app first ?

Did you get the “Welcome back” message at the top of the screen?

Getting GPGS setup is pretty hard.  You need to read the tutorial carefully about all the setup steps.  Unfortunately, I can’t see your google play console and your setup, but your code works once you get the setup working.