API Index
Overview
Setup
Initialize
Achievements
Challenges
Leaderboards
Scores
Players
Real-Time Game
Turn-Based Game
Before you can add Leaderboards to your game, you must configure Leaderboards in iTunes Connect and the GameKit Plugin must be setup as well as initialized.
Leaderboards Commands
Show Leaderboards UI
Get Leaderboards
Get Leaderboard Sets
Get Default LeaderboardID
Request Set Default LeaderboardID
Get Leaderboard Image
Show Leaderboards UI
Comments: Show Game Center Leaderboards UI.
Function: show( (string) “gameCenterLeaderboardsUI”, (table) { leaderboardID= (string) “com.yourSite.yourGame.leaderboard” } )
Param Table Keys: (string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
Callback Events: none
1 2 3 |
gameKit.show( "gameCenterLeaderboardsUI", { leaderboardID="com.yourSite.yourGame.leaderboard" } ) |
Get Leaderboards
Comments: Get Game Center Leaderboards.
Function: get( (string) “leaderboards”, (table) { listener= (function) onLeaderboardsCallback } )
Param Table Keys: (function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “leaderboardList” – Leaderboard list event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(number) leaderboardsCount – Number of leaderboard tables in the leaderboards array.
(array) leaderboards – Array of leaderboard tables.
Leaderboard Table Keys:
(string) title – A localized Game Center title for the leaderboard you created for your game on iTunes Connect.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(string) groupIdentifier – A unique Game Center identifier string for the group the leaderboard is part of. If your game was configured to be part of a group in iTunes Connect, this property holds the identifier you assigned to the group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
local function onLeaderboardsCallback( event ) if( event.type == "error" ) then print( 'onLeaderboardsCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onLeaderboardsCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "leaderboardList" ) then for i = 1, event.leaderboardsCount do print( 'onLeaderboardsCallback leaderboard ' .. tostring(i) .. ' title = ' .. event.leaderboards[i].title ) print( 'onLeaderboardsCallback leaderboard ' .. tostring(i) .. ' leaderboardID = ' .. event.leaderboards[i].leaderboardID ) print( 'onLeaderboardsCallback leaderboard ' .. tostring(i) .. ' groupIdentifier = ' .. event.leaderboards[i].groupIdentifier ) end end return true end gameKit.get( "leaderboards", { listener=onLeaderboardsCallback } ) |
Get Leaderboard Sets
Comments: Get Game Center Leaderboard Sets.
Function: get( (string) “leaderboardSets”, (table) { listener= (function) onLeaderboardsCallback } )
Param Table Keys: (function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “leaderboardSetList” – Leaderboard Set list event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(number) leaderboardSetsCount – Number of leaderboard set tables in the leaderboardSets array.
(array) leaderboardSets – Array of leaderboard set tables.
Leaderboard Set Table Keys:
(string) title – A localized Game Center title for the leaderboard you created for your game on iTunes Connect.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(string) groupIdentifier – A unique Game Center identifier string for the group the leaderboard is part of. If your game was configured to be part of a group in iTunes Connect, this property holds the identifier you assigned to the group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
local function onLeaderboardsCallback( event ) if( event.type == "error" ) then print( 'onLeaderboardsCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onLeaderboardsCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "leaderboardList" ) then for i = 1, event.leaderboardsCount do print( 'onLeaderboardsCallback leaderboardSet ' .. tostring(i) .. ' title = ' .. event.leaderboards[i].title ) print( 'onLeaderboardsCallback leaderboardSet ' .. tostring(i) .. ' leaderboardID = ' .. event.leaderboards[i].leaderboardID ) print( 'onLeaderboardsCallback leaderboardSet ' .. tostring(i) .. ' groupIdentifier = ' .. event.leaderboards[i].groupIdentifier ) end end return true end gameKit.get( "leaderboardSets", { listener=onLeaderboardsCallback } ) |
Get Default LeaderboardID
Comments: Get Game Center default leaderboardID.
Function: (function) get( (string) “defaultLeaderboardID”, (table) { listener= (function) onLeaderboardsCallback } )
Param Table Keys: (function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “defaultLeaderboardID” – Default leaderboardID event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
local function onLeaderboardsCallback( event ) if( event.type == "error" ) then print( 'onLeaderboardsCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onLeaderboardsCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "defaultLeaderboardID" ) then print( 'onLeaderboardsCallback event.leaderboardID = ' .. event.leaderboardID ) end return true end gameKit.get( "defaultLeaderboardID", { listener=onLeaderboardsCallback } ) |
Request Set Default LeaderboardID
Comments: Set Game Center default leaderboardID.
Function: (function) request( (string) “setDefaultLeaderboardID”, (table) { listener= (function) onLeaderboardsCallback } )
Param Table Keys: (function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “success” – GameKit success event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(string) successDescription – GameKit success description string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
-- mock data, get real leaderboardID from Game Center mockLeaderboardID = "com.yourSite.yourGame.leaderboard" local function onLeaderboardsCallback( event ) if( event.type == "error" ) then print( 'onLeaderboardsCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onLeaderboardsCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "success" ) then print( 'onLeaderboardsCallback event.successDescription = ' .. event.successDescription ) end return true end gameKit.request( "setDefaultLeaderboardID", { leaderboardID=mockLeaderboardID, listener=onLeaderboardsCallback } ) |
Get Leaderboard Image
Comments: Get Game Center leaderboard image.
Function: (function) get( (string) “leaderboardImage”, (table) { leaderboardID= (string) “com.yourSite.yourGame.leaderboard”, listener= (function) onLeaderboardsCallback } )
Param Table Keys:
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “leaderboardImage” – Leaderboard image event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(display object) image – An image to display for the leaderboard.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
local leaderboardImage = nil -- mock data, get real leaderboardID from Game Center mockLeaderboardID = "com.yourSite.yourGame.leaderboard" local function onLeaderboardsCallback( event ) if( event.type == "error" ) then print( 'onLeaderboardsCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onLeaderboardsCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "leaderboardImage" ) then print( 'onLeaderboardsCallback event.leaderboardID = ' .. event.leaderboardID ) leaderboardImage = event.image leaderboardImage = display.contentCenterX leaderboardImage = display.contentCenterY end return true end gameKit.get( "leaderboardImage", { leaderboardID=mockLeaderboardID, listener=onLeaderboardsCallback } ) |