[help error] gameNetwork.request("isConnected") doesn't work :(

How to create a check function that the user logged in or not? I’m using isConnected but failed :(, my button only do login, not logout.

this is my code: 

local function loginLogoutListener(event) local function loginListener(event1) -- Checks to see if there was an error with the login. if event1.isError then --event.target:setLabel("login") else event.target:setLabel("Logout") end end if gameNetwork.request("isConnected") then gameNetwork.request("logout") event.target:setLabel("Login") else -- Tries to login the user, if there is a problem then it will try to resolve it. eg. Show the log in screen. gameNetwork.request("login", { listener = loginListener, userInitiated = true }) end end

Hi @azhar,

My first question is, why do you have the “loginListener” function nested within a “loginLogoutListener” function? Is that necessary, and if so, why? You should be able to build one function that handles this entire process, without using a nested function. In other words, by guess is that there’s a scope or variable reference issue that is preventing this from working as you intend.

Best regards,

Brent

I just following Corona SDK sample code for this button. What should? Idk :(… however the problem is “isConnected” didn’t work and not listen when the user logged in.

https://github.com/coronalabs/plugins-source-gamenetwork-google/blob/master/Corona/main.lua

Hi @azhar,

Do other aspects of your project work, or is only the “isConnected” part failing? Did you properly include the Google Play Services plugin and all of the various permission and setup properties required for using it? Which version of Corona SDK are you using?

Thanks,

Brent

Google Play service is working, user can login, leaderboards and achievements is work, I think it’s just “isConnected” that doesn’t work. Btw, I test it on my Android device, not in the emulator. For now I use version 2646. Just want to know, have you try the code? Is it working properly? If I still can’t solve this problem, do you think it’s okay to not add logout feature? Thanks for your reply :)…

Hi @azhar,

Can you please add some print() statements to help debug this? In particular, add print() statements to confirm that the conditional blocks are being reached at all, and if so, what the value(s) of “event” are.

Thanks,

Brent

Sorry for late reply :(, I do end up with not add “Log Out” feature since it is not necessary…

Hi @azhar,

My first question is, why do you have the “loginListener” function nested within a “loginLogoutListener” function? Is that necessary, and if so, why? You should be able to build one function that handles this entire process, without using a nested function. In other words, by guess is that there’s a scope or variable reference issue that is preventing this from working as you intend.

Best regards,

Brent

I just following Corona SDK sample code for this button. What should? Idk :(… however the problem is “isConnected” didn’t work and not listen when the user logged in.

https://github.com/coronalabs/plugins-source-gamenetwork-google/blob/master/Corona/main.lua

Hi @azhar,

Do other aspects of your project work, or is only the “isConnected” part failing? Did you properly include the Google Play Services plugin and all of the various permission and setup properties required for using it? Which version of Corona SDK are you using?

Thanks,

Brent

Google Play service is working, user can login, leaderboards and achievements is work, I think it’s just “isConnected” that doesn’t work. Btw, I test it on my Android device, not in the emulator. For now I use version 2646. Just want to know, have you try the code? Is it working properly? If I still can’t solve this problem, do you think it’s okay to not add logout feature? Thanks for your reply :)…

Hi @azhar,

Can you please add some print() statements to help debug this? In particular, add print() statements to confirm that the conditional blocks are being reached at all, and if so, what the value(s) of “event” are.

Thanks,

Brent

Sorry for late reply :(, I do end up with not add “Log Out” feature since it is not necessary…