From The Blog: Update on the new GPGS v2 plugin

Hi! First of all, before calling any methods from the plugin check the connection state because the result of isConnected() method can be false and you probably will get this error. Second, if you didn’t update your app at the https://play.google.com/apps/publish or at the https://console.developers.google.com/, or you didn’t set up the project completely, the plugin will not allow you to call the methods.

Probably this would help you with debugging your application

function m.setTopScore( score, leaderboardIndex ) if isiOS then local categories = { "com.frikado.leaderboard.park", "com.frikado.leaderboard.room" } gameNetwork.request( "setHighScore", { localPlayerScore = { category=categories[leaderboardIndex], value=score }}) elseif isAndroid then local function submitCallback(event) native.showAlert( "Submit Event!", "Set Top Score", { "OK" } ) end if gpgs.isConnected() then gpgs.leaderboards.submit({ leaderboardId = leaderboardIDs[leaderboardIndex], score = score, listener = submitCallback }) else native.showAlert('Is connected?', gpgs.isConnected() and 'Yes' or 'No', {'OK'}) end end end function m.showLeaderboards() if isiOS then gameNetwork.show( "leaderboards" ) elseif isAndroid then local function showCallback(event) native.showAlert( "Show Event!", "Show Leaderboard", { "OK" } ) end if gpgs.isConnected() then gpgs.leaderboards.show({listener = showCallback}) else native.showAlert('Is connected?', gpgs.isConnected() and 'Yes' or 'No', {'OK'}) end end end

Thanks for your reply Kirill, after trying your suggestion, I get the crash now on the line that calls this:

if gpgs.isConnected() then

I will go over the console stuff again.  :rolleyes:

Any updates?  :frowning:

Hello guys!

I know you are super busy but there are some issues with gpgs v2.

I use gpgs for saving / loading players progress.

Everything is fine with the old plugin.

With the new plugin:

  1. I don’t see the welcome and chose account boxes the first time (or ever) the app starts. Is it normal?

  2. If I delete / reinstall the game, I have to start the game twice until I get my progress back.

The first time fails to move to gpgsSnapshotOpenForReadListener function I guess.

Something wrong with my code?

I’m sorry, I don’t have time right now for logs but maybe someone ( Mr. Rob Miracle :slight_smile: ) could check my code.

  

-- build.settings ["plugin.gpgs.v2"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, -- main.lua gpgs = require( "plugin.gpgs.v2" ) -- menu.lua local function gpgsSnapshotOpenForReadListener( event ) if not event.isError then local readlevels = gpgs.snapshots.getSnapshot (event.snapshotId) local prevlevels = json.decode( readlevels.contents.read() ) if prevlevels == nil then readlevels.contents.write( json.encode( makeallzero ) ) gpgs.snapshots.save({ snapshotId = event.snapshotId, listener = gpgsSnapshotAfter }) else if prevlevels \> nowlevels then saveFile("nowlevels.txt", prevlevels) end end end end local function gpgsLoginListener( event ) gpgs.snapshots.open({ filename = "save1", create = true, listener = gpgsSnapshotOpenForReadListener }) gpgs.snapshots.open({ filename = "save2", create = true, listener = gpgsSnapshotOpenForReadListener2 }) end gpgs.login( { userInitiated = true, listener = gpgsLoginListener } )

I believe there were multiple ways to deal with snapshots in the V1 plugin, but for V2, those seem to be a bit more limited. Consider this code:

local myTable = { play = 1 } local snapshotFilename = "snapshot1" local data = json.encode( myTable ) local function gpgsSnapshotOpenForReadListener( event ) print( "snapshot open event:", json.prettify(event) ) if not event.isError then local data = event.snapshot.contents.read() native.showAlert('Snapshots', 'Reading was ' .. (event.isError and 'unsuccessful' or 'successful') .. ',', { 'OK'}) end end local function gpgsSnapshotAfterSaveListener( event ) native.showAlert('Snapshots', 'Saving was ' .. (event.isError and 'unsuccessful' or 'successful') .. '.', {'OK'}) end function myData.openSnapshot() print("Opening snapshot") gpgs.snapshots.open({ filename = snapshotFilename, listener = gpgsSnapshotOpenForReadListener }) end local function gpgsSnapshotOpenForSaveListener( event ) print("open for save listener", json.prettify( event )) if not event.isError then event.snapshot.contents.write(data) -- Write new data as a JSON string into the snapshot gpgs.snapshots.save({ snapshot = event.snapshot, description = 'Save slot ' .. snapshotFilename, listener = gpgsSnapshotAfterSaveListener }) end end function myData.saveSnapshot() print("saving snapshhot") gpgs.snapshots.open({ -- Open the save slot filename = snapshotFilename, create = true, -- Create the snapshot if it's not found listener = gpgsSnapshotOpenForSaveListener }) end

Try this method of reading/writing snapshots.

Rob

Hi Rob,

There is a gpgs.multiplayer.realtime.show() function which _“Shows a view that will display a “waiting room” screen that shows the progress of participants joining a real-time multiplayer room”. _I’m using it and a waiting room is showed. Problem is how to close it programmatically before room is fully connected. Android documentation says: 

When a player clicks the  Start Playing  option, the waiting room UI is not automatically dismissed for the other players in the game. To dismiss the waiting room for the other players, your game should send a reliable real-time message to the other players to indicate that the game is starting early. When your game receives the message, it should dismiss the waiting room UI.

How should I dismiss the waiting room UI?

Thank you for your support

No replies?? :frowning:

This is the document for gpgs.multiplayer.realtime.show( params )

minPlayersRequired (optional)

Number. If desired, the waiting room can allow the user to start playing the game even before the room is fully connected, and this is controlled by the minPlayersRequiredparameter. If at least this many participants including the current player are connected to the room, a “start” menu item will be enabled in the waiting room UI. Setting minPlayersRequired to 0 means that the item will always be available, while omitting this parameter will disable the item entirely. Note that if you allow any user to start early, you’ll need to handle the situation by explicitly telling the other connected peers that the game is now starting.

 

Is there any example of how to tell the other connected peers that game is starting and dismiss the waiting UI?

 

Thank you