extension-gpgs

Namespace: gpgs Language: Lua Type: Extension

Functions and constants for interacting with Google Play Game Services (GPGS) APIs

API

gpgs.is_supported

Type: FUNCTION Check if Google Play Services are available & ready on the device.

Returns

Examples

if gpgs then
  local is_supported = gpgs.is_supported()
end

gpgs.login

Type: FUNCTION Login to GPGS using a button.

Examples

Log in to GPGS using a button:

if gpgs then
  gpgs.login()
end

gpgs.silent_login

Type: FUNCTION Silent login to GPGS. This function is trying to retrieve the currently signed-in player’s account.

Examples

function init(self)
  if gpgs then
    gpgs.silent_login()
  end
end

gpgs.get_display_name

Type: FUNCTION Get the current GPGS player display name.

Returns

Examples

if gpgs then
  local name = gpgs.get_display_name()
end

gpgs.get_id

Type: FUNCTION Get the current GPGS player id.

Returns

Examples

if gpgs then
  local id = gpgs.get_id()
end

gpgs.get_server_auth_code

Type: FUNCTION Returns a one-time server auth code to send to your web server which can be exchanged for access token Token can be retrieved only if gpgs.request_server_auth_code set to 1 and gpgs.client is set.

Returns

Examples

if gpgs then
  local server_auth_code = gpgs.get_server_auth_code()
end

gpgs.is_logged_in

Type: FUNCTION Check if a user is logged in currently.

Returns

Examples

if gpgs then
  local is_loggedin = gpgs.is_logged_in()
end

gpgs.set_callback

Type: FUNCTION Set callback for receiving messages from GPGS.

Parameters

Examples

function callback(self, message_id, message)
  if message_id == gpgs.MSG_SIGN_IN or message_id == gpgs.MSG_SILENT_SIGN_IN then
    if message.status == gpgs.STATUS_SUCCESS then
    -- do something after login
    end
  elseif message_id == gpgs.MSG_LOAD_SNAPSHOT then
  -- do something when a save was loaded
  end
end

function init(self)
  gpgs.set_callback(callback)
end

function init(self)
  gpgs.set_callback(nil) -- remove callback
end

gpgs.snapshot_display_saves

Type: FUNCTION Provides a default saved games selection user interface.

Parameters

Examples

if gpgs then
  gpgs.snapshot_display_saves("Choose the save of the game", false, true, 10)
end

gpgs.snapshot_open

Type: FUNCTION Opens a snapshot with the given saveName. If createIfNotFound is set to true, the specified snapshot will be created if it does not already exist.

Parameters

Default value is gpgs.RESOLUTION_POLICY_LAST_KNOWN_GOOD

Examples

if gpgs then
  gpgs.snapshot_open("my_save_1", true, gpgs.RESOLUTION_POLICY_LONGEST_PLAYTIME)
end

gpgs.snapshot_commit_and_close

Type: FUNCTION Save the currently opened save on the server and close it.

Parameters

Examples

if gpgs then
  local png_img, w, h = screenshot.png()
  gpgs.snapshot_commit_and_close({
      coverImage = png_img,
      description = "LEVEL 31, CAVE",
      playedTime = 12345667,
      progressValue = 657
  })
end

gpgs.snapshot_get_data

Type: FUNCTION Returns the currently opened snapshot data.

Returns

Examples

if gpgs then
  local bytes, error_message = gpgs.snapshot_get_data()
  if not bytes then
      print("snapshot_get_data ERROR:", error_message)
  else
      print("snapshot_get_data",bytes)
      -- Do something with your data
  end
end

gpgs.snapshot_set_data

Type: FUNCTION Sets the data for the currently opened snapshot.

Parameters

Returns

Examples

  if gpgs then
    local success, error_message = gpgs.snapshot_set_data(my_data)
    if not success then
        print("snapshot_set_data ERROR:", error_message)
    end
  end

gpgs.snapshot_is_opened

Type: FUNCTION Check if a snapshot was opened.

Returns

Examples

if gpgs then
  local is_opened = gpgs.snapshot_is_opened()
end

gpgs.snapshot_get_max_image_size

Type: FUNCTION Returns the maximum data size per snapshot cover image in bytes.

Returns

Examples

if gpgs then
  local image_size = gpgs.snapshot_get_max_image_size()
end

gpgs.snapshot_get_max_save_size

Type: FUNCTION Returns the maximum data size per snapshot in bytes.

Returns

Examples

if gpgs then
  local data_size = gpgs.snapshot_get_max_save_size()
end

gpgs.snapshot_get_conflicting_data

Type: FUNCTION Returns the conflicting snapshot data.

Returns

Examples

if gpgs then
  local bytes, error_message = gpgs.snapshot_get_conflicting_data()
  if not bytes then
      print("snapshot_get_conflicting_data ERROR:", error_message)
  else
      print("snapshot_get_conflicting_data:",bytes)
      -- Do something with conflicting data data
  end
end

gpgs.snapshot_resolve_conflict

Type: FUNCTION Resolves a conflict using the data from the provided snapshot.

Parameters

Examples

if gpgs then
  gpgs.snapshot_resolve_conflict(self.conflictId, gpgs.SNAPSHOT_CONFLICTING)
end

gpgs.leaderboard_submit_score

Type: FUNCTION Submit a score to a leaderboard for the currently signed-in player.

Parameters

gpgs.leaderboard_get_top_scores

Type: FUNCTION Asynchronously gets the top page of scores for a leaderboard.

Parameters

gpgs.leaderboard_get_player_centered_scores

Type: FUNCTION Asynchronously gets a player-centered page of scores for a leaderboard.

Parameters

gpgs.leaderboard_show

Type: FUNCTION Show a leaderboard for a game specified by a leaderboardId.

Parameters

gpgs.leaderboard_list

Type: FUNCTION Show the list of leaderboards.

gpgs.leaderboard_get_player_score

Type: FUNCTION Asynchronously gets a player-centered page of scores for a leaderboard.

Parameters

gpgs.achievement_reveal

Type: FUNCTION Reveals a hidden achievement to the current player.

Parameters

gpgs.achievement_unlock

Type: FUNCTION Unlocks an achievement for the current player.

Parameters

gpgs.achievement_set

Type: FUNCTION Sets an achievement to have at least the given number of steps completed.

Parameters

gpgs.achievement_increment

Type: FUNCTION Increments an achievement by the given number of steps.

Parameters

gpgs.achievement_show

Type: FUNCTION Show achivements

gpgs.achievement_get

Type: FUNCTION Get information about all achievement’s state asynchronously. Result return to callback previously set by gpgs.set_callback with message_id == gpgs.MSG_ACHIEVEMENTS. Result is array of tables which contain following fields

gpgs.event_increment

Type: FUNCTION Increments an event specified by eventId by the given number of steps

Parameters

gpgs.event_get

Type: FUNCTION Get information about all events asynchronously. Result returns to callback previously set by gpgs.set_callback with message_id == gpgs.MSG_GET_EVENTS. Result is array of tables which contain following fields

RESOLUTION_POLICY_MANUAL

Type: VARIABLE Official GPGS documentation for this constant

RESOLUTION_POLICY_LONGEST_PLAYTIME

Type: VARIABLE Official GPGS documentation for this constant

RESOLUTION_POLICY_LAST_KNOWN_GOOD

Type: VARIABLE Official GPGS documentation for this constant

RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED

Type: VARIABLE Official GPGS documentation for this constant

RESOLUTION_POLICY_HIGHEST_PROGRESS

Type: VARIABLE Official GPGS documentation for this constant

MSG_SIGN_IN

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation after calling gpgs.login()

MSG_SILENT_SIGN_IN

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation after calling gpgs.silent_login()

MSG_SHOW_SNAPSHOTS

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation after calling gpgs.snapshot_display_saves()

MSG_LOAD_SNAPSHOT

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation after calling gpgs.snapshot_open()

MSG_SAVE_SNAPSHOT

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation after calling gpgs.snapshot_commit_and_close()

MSG_GET_SERVER_TOKEN

Type: VARIABLE The message type that GPGS sends when finishing the asynchronous operation of server token retrieval

STATUS_SUCCESS

Type: VARIABLE An operation success.

STATUS_FAILED

Type: VARIABLE An operation failed. Check the error field in the massage table.

STATUS_CREATE_NEW_SAVE

Type: VARIABLE A user wants to create new save as a result of gpgs.snapshot_display_saves() method. Turn off this button in gpgs.snapshot_display_saves() if you don’t want to have this functionality.

STATUS_CONFLICT

Type: VARIABLE The result of the calling gpgs.snapshot_open() or ‘gpgs.snapshot_resolve_conflict()’ is a conflict. You need to make decision on how to solve this conflict using ‘gpgs.snapshot_resolve_conflict()’.

SNAPSHOT_CURRENT

Type: VARIABLE The second parameter for ‘gpgs.snapshot_resolve_conflict()’ method, which means that you want to choose the current snapshot as a snapshot for conflict solving.

SNAPSHOT_CONFLICTING

Type: VARIABLE The second parameter for ‘gpgs.snapshot_resolve_conflict()’ method, which means that you want to choose the conflicting snapshot as a snapshot for conflict solving.

ERROR_STATUS_SNAPSHOT_NOT_FOUND

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant

ERROR_STATUS_SNAPSHOT_CREATION_FAILED

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant

ERROR_STATUS_SNAPSHOT_CONTENTS_UNAVAILABLE

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant

ERROR_STATUS_SNAPSHOT_COMMIT_FAILED

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant

ERROR_STATUS_SNAPSHOT_FOLDER_UNAVAILABLE

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant

ERROR_STATUS_SNAPSHOT_CONFLICT_MISSING

Type: VARIABLE This constant is used in message.error_status table when MSG_LOAD_SNAPSHOT is STATUS_FAILED. Official GPGS documentation for this constant