Can only call the gameNetwok.init function once?

I setup Google Play Game Services and it works and starts with a button to initialize it (sign in button) but if the user signs out then hits the button it doesn’t work (no errors). If the app is restarted the button works again. Here is my code:

[lua]

    local playerName

    function loadLocalPlayerCallback( event )

       playerName = event.data.alias

       saveSettings()  --save player data locally using your own “saveSettings()” function

    end

    function gameNetworkLoginCallback ( event )

        print(“LOGINCALLBACK”)

       gameNetwork.request( “loadLocalPlayer”, { listener=loadLocalPlayerCallback } )

       return true

    end

    function gpgsInitCallback ( event )

        print(“INITCALLBACK”)

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

    end

    function gameNetworkSetup ()

       if ( system.getInfo(“platformName”) == “Android” ) then

              print(“GAMENETWORKSETUP”)

          gameNetwork.init( “google”, gpgsInitCallback )

       else

          gameNetwork.init( “gamecenter”, gameNetworkLoginCallback )

       end

    end

[/lua]

I call gameNetworkSetup when the button is tapped. This would mean that if the user signed out they wouldn’t be able to access the leader boards anymore until they exit the app. Any help would be appreciated!

I think you only need to call gameNetwork.init once after the app is launched.  You can request “login” as well as “logout” without ever calling gameNetwork.init again.

With my app, I call gameNetwork.init once upon launch of the app in main.lua.  I call gameNetwork.request “login” as well as “logout” in a scene where user chooses to either sign in or out.

Naomi

Aahh I see. I made it so that I call gameNetworkSetup in main.lua and this is the function for the login button but it still doesn’t do anything:

[lua]

            local function login()

                gameNetwork.request( “login” )

            end

[/lua]

You’re missing the login call back handler.

Okay I added a listener to the function, here is my new code:

[lua]

            local function loginHandler ( event )

                print(“LOGINCALLBACK”)

                return true

            end

            local function login()

                print(“LOGIN”)

                gameNetwork.request( “login”, {listener=loginHandler} )

            end

[/lua]

But it still does nothing, but it prints both “LOGIN” and “LOGINCALLBACK” on the device. I wasn’t sure what to put in the callback. Is anything supposed to be there?

Please read this blog post:

http://www.coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/

You probably should be checking the results of the event table in each of the call backs to see if event.isError is true or not and looking at the other return values (google for “Corona print table” to find sample code for printing out the table).  You won’t necessarily need to do anything after a login.  You can if you want and the blog post shows how to get the player’s network name (alias) after a login.

I have been following that tutorial and my function is identical to theirs now. I added the loadLocalPlayer request but I’m not sure what that does, the only thing is that the stuff inside of the listener for it isn’t getting printed. Here’s my updated code:

[lua]

            local function loadPlayerCallback(event)

                print(“LOAD LOCAL PLAYER”) – this isn’t getting printed on device

                print(event.isError) --neither is this

            end

            local function loginHandler ( event )

                print(event.isError, “IsError”)

                print(“LOGINCALLBACK”)

                gameNetwork.request( “loadLocalPlayer”, { listener=loadPlayerCallback } )

                return true

            end

            local function login()

                print(“LOGIN”)

                gameNetwork.request( “login”, {listener=loginHandler} )

            end

[/lua]

I think you only need to call gameNetwork.init once after the app is launched.  You can request “login” as well as “logout” without ever calling gameNetwork.init again.

With my app, I call gameNetwork.init once upon launch of the app in main.lua.  I call gameNetwork.request “login” as well as “logout” in a scene where user chooses to either sign in or out.

Naomi

Aahh I see. I made it so that I call gameNetworkSetup in main.lua and this is the function for the login button but it still doesn’t do anything:

[lua]

            local function login()

                gameNetwork.request( “login” )

            end

[/lua]

You’re missing the login call back handler.

Okay I added a listener to the function, here is my new code:

[lua]

            local function loginHandler ( event )

                print(“LOGINCALLBACK”)

                return true

            end

            local function login()

                print(“LOGIN”)

                gameNetwork.request( “login”, {listener=loginHandler} )

            end

[/lua]

But it still does nothing, but it prints both “LOGIN” and “LOGINCALLBACK” on the device. I wasn’t sure what to put in the callback. Is anything supposed to be there?

Please read this blog post:

http://www.coronalabs.com/blog/2013/06/25/tutorial-introducing-google-play-game-services/

You probably should be checking the results of the event table in each of the call backs to see if event.isError is true or not and looking at the other return values (google for “Corona print table” to find sample code for printing out the table).  You won’t necessarily need to do anything after a login.  You can if you want and the blog post shows how to get the player’s network name (alias) after a login.

I have been following that tutorial and my function is identical to theirs now. I added the loadLocalPlayer request but I’m not sure what that does, the only thing is that the stuff inside of the listener for it isn’t getting printed. Here’s my updated code:

[lua]

            local function loadPlayerCallback(event)

                print(“LOAD LOCAL PLAYER”) – this isn’t getting printed on device

                print(event.isError) --neither is this

            end

            local function loginHandler ( event )

                print(event.isError, “IsError”)

                print(“LOGINCALLBACK”)

                gameNetwork.request( “loadLocalPlayer”, { listener=loadPlayerCallback } )

                return true

            end

            local function login()

                print(“LOGIN”)

                gameNetwork.request( “login”, {listener=loginHandler} )

            end

[/lua]