API Index
Overview
Setup
Initialize
Achievements
Challenges
Leaderboards
Scores
Players
Real-Time Game
Turn-Based Game
Before you can use Scores Commands in your game, you must configure Leaderboards in iTunes Connect and the GameKit Plugin must be setup as well as initialized.
Scores Commands
Send Score
Get Scores
Get Scores With Players
Send Score
Comments: Send Score to Game Center. Note the optional Param table key, context.
Function: (function) send( (string) “score”, (table) { leaderboardID= (string) “com.yourSite.yourGame.leaderboard”, value= (number) 68, (optional key) context= (number) 42, listener= (function) onScoresCallback } )
Param Table Keys:
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(number) value – A score number value earned by the local player. You determine how your scores are formatted when you define the leaderboard on iTunes Connect.
(number) context (optional key) – A number value used by your game. The context property is stored and returned to your game, but is otherwise ignored by Game Center. It allows your game to associate an arbitrary 64-bit unsigned integer value with the score data reported to Game Center. You decide how this context value is interpreted by your game.
(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 17 18 |
-- mock data mockLeaderboardID = "com.yourSite.yourGame.leaderboard" mockScore = 68 mockContext = 42 local function onScoresCallback( event ) if( event.type == "error" ) then print( 'onScoresCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onScoresCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "success" ) then print( 'onScoresCallback event.successDescription = ' .. event.successDescription ) end return true end gameKit.send( "score", { leaderboardID=mockLeaderboardID, value=mockScore, context=mockContext, listener=onScoresCallback } ) |
Get Scores
Comments: Get Game Center Scores. Note the score filters playerScope, timeScope and range to modify your results.
Function: (function) get( (string) “score”, (table) { leaderboardID= (string) “com.yourSite.yourGame.leaderboard”, playerScope= (string) “Global”, timeScope= (string) “AllTime”, range= (table) {(number) 1, (number) 5}, listener= (function) onScoresCallback } )
Param Table Keys:
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(string) playerScope – A filter string used to get scores for players on Game Center. playerScope=”Global” or playerScope=”FriendsOnly”. “Global” will get all player’s scores and “FriendsOnly” will only get local player’s friends scores.
(string) timeScope – A filter string used to get scores that were posted to Game Center within a specific period of time. timeScope=”Today” or timeScope=”Week” or timeScope=”AllTime”. “Today” will get player scores recorded in the past 24 hours, “Week” will get player scores recorded in the past week, “AllTime” will get player scores recorded for all time.
(table) range – A filter table of minimum and maximum numbers used to get scores within a specific range that were posted to Game Center. range={minimum, maximum}, the minimum range number is 1 and the maximum range number is 100. For example, if you specified a range of {1,10}, you would get the top ten scores from first to tenth.
(function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “scoreList” – Score list event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(number) scoresCount – Number of score tables in the scores array.
(array) scores – Array of score tables.
Score Table Keys:
(string) playerID – A string assigned by Game Center to uniquely identify a player.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(number) rank – A position of the player’s score on the Game Center leaderboard with 1 being the best score, 2 being the second best, and so on.
(string) formattedValue – A player’s score as a localized string. You determine how your scores are formatted when you define the leaderboard on iTunes Connect.
(number) value – A score number value earned by the player.
(number) context – A number value used by your game. The context property is stored and returned to your game, but is otherwise ignored by Game Center. It allows your game to associate an arbitrary 64-bit unsigned integer value with the score data reported to Game Center. You decide how this context value is interpreted by your game.
(string) date – A date and time string of when the score was posted to Game Center.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
-- mock data mockLeaderboardID = "com.yourSite.yourGame.leaderboard" local function onScoresCallback( event ) if( event.type == "error" ) then print( 'onScoresCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onScoresCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "scoreList" ) then for i = 1, e.scoresCount do print( 'onScoresCallback score ' .. tostring(i) .. ' playerID = ' .. event.scores[i].playerID ) print( 'onScoresCallback score ' .. tostring(i) .. ' leaderboardID = ' .. event.scores[i].leaderboardID ) print( 'onScoresCallback score ' .. tostring(i) .. ' rank = ' .. tostring(event.scores[i].rank) ) print( 'onScoresCallback score ' .. tostring(i) .. ' formattedValue = ' .. event.scores[i].formattedValue ) print( 'onScoresCallback score ' .. tostring(i) .. ' value = ' .. tostring(event.scores[i].value) ) print( 'onScoresCallback score ' .. tostring(i) .. ' context = ' .. tostring(event.scores[i].context) ) print( 'onScoresCallback score ' .. tostring(i) .. ' date = ' .. event.scores[i].date ) end end return true end gameKit.get( "scores", { leaderboardID=mockLeaderboardID, playerScope="Global", timeScope="AllTime", range={1,5}, listener=onScoresCallback } ) |
Get Scores With Players
Comments: Get Game Center Scores of players with playerIDs.
Function: (function) get( (string) “scoresWithPlayers”, (table) { leaderboardID= (string) “com.yourSite.yourGame.leaderboard”, playerIDs= (table) {(string) “G:2073637149”}, timeScope= (string) “AllTime”, listener= (function) onScoresCallback } )
Param Table Keys:
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(table) playerIDs – An array of 1 or more playerID strings to get scores for.
(string) timeScope – A filter string used to get scores that were posted to Game Center within a specific period of time. timeScope=”Today” or timeScope=”Week” or timeScope=”AllTime”. “Today” will get player scores recorded in the past 24 hours, “Week” will get player scores recorded in the past week, “AllTime” will get player scores recorded for all time.
(function) listener – A function to receive callback events.
Callback Events:
Event Name: (string) “gameKitLibrary”
Event Type:
(string) “error” – GameKit error event.
(string) “scoreList” – Score list event.
Event Properties:
(number) errorCode – GameKit GKErrorCode number.
(string) errorDescription – GameKit error description string.
(number) scoresCount – Number of score tables in the scores array.
(array) scores – Array of score tables.
Score Table Keys:
(string) playerID – A string assigned by Game Center to uniquely identify a player.
(string) leaderboardID – A unique Game Center leaderboard identifier string you created for your game on iTunes Connect.
(number) rank – A position of the player’s score on the Game Center leaderboard with 1 being the best score, 2 being the second best, and so on.
(string) formattedValue – A player’s score as a localized string. You determine how your scores are formatted when you define the leaderboard on iTunes Connect.
(number) value – A score number value earned by the player.
(number) context – A number value used by your game. The context property is stored and returned to your game, but is otherwise ignored by Game Center. It allows your game to associate an arbitrary 64-bit unsigned integer value with the score data reported to Game Center. You decide how this context value is interpreted by your game.
(string) date – A date and time string of when the score was posted to Game Center.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
-- mock data mockLeaderboardID = "com.yourSite.yourGame.leaderboard" mockLocalPlayerID = "G:2073637149" mockFriendPlayerID = "G:9125286970" local function onScoresCallback( event ) if( event.type == "error" ) then print( 'onScoresCallback event.errorCode = ' .. tostring(event.errorCode) ) print( 'onScoresCallback event.errorDescription = ' .. event.errorDescription ) elseif( event.type == "scoreList" ) then for i = 1, e.scoresCount do print( 'onScoresCallback score ' .. tostring(i) .. ' playerID = ' .. event.scores[i].playerID ) print( 'onScoresCallback score ' .. tostring(i) .. ' leaderboardID = ' .. event.scores[i].leaderboardID ) print( 'onScoresCallback score ' .. tostring(i) .. ' rank = ' .. tostring(event.scores[i].rank) ) print( 'onScoresCallback score ' .. tostring(i) .. ' formattedValue = ' .. event.scores[i].formattedValue ) print( 'onScoresCallback score ' .. tostring(i) .. ' value = ' .. tostring(event.scores[i].value) ) print( 'onScoresCallback score ' .. tostring(i) .. ' context = ' .. tostring(event.scores[i].context) ) print( 'onScoresCallback score ' .. tostring(i) .. ' date = ' .. event.scores[i].date ) end end return true end gameKit.get( "scoresWithPlayers", { leaderboardID=mockLeaderboardID, playerIDs={mockLocalPlayerID, mockFriendPlayerID}, timeScope="AllTime", listener=onScoresCallback } ) |