Game Center "loadScores" returning nil?

Hi, I have been making my custom leaderboard and got the Gui working for it a while ago. My app is successfully on the Apple App Store. My leaderboards have not been loading and I have been trying to fix this issue for a while now. I have tested in testflight using game_network.show(“leaderboards”,…) so I know the leaderboard is existent and it successfully sets high scores, but when I use this code:

function Load\_Scores(scope,timescope,range) --scope = "Global" or "FriendsOnly --timescope = "AllTime", "Week", or "Today"" print("Loading...") return game\_network.request("loadScores", { leaderboard = { category = 'Game.HighScore', playerScope = scope or "Global", timeScope = timescope or "AllTime", range = range or {1,25}, playerCentered = false }, listener = function(event) local d = event.data for i,k in pairs (d or {}) do print(i,k) end return event.data end }) end function Update\_Leaderboard\_Data() if not Leaderboard\_Data then Leaderboard\_Data = {} end for q,w in pairs ({"AllTime","Week","Today"}) do local t = Load\_Scores("Global",w) print(t) table.sort(t or {},function(a,b) return a.rank \< b.rank end) Leaderboard\_Data[w] = t if not Leaderboard\_Data[w] then print(w) print("No Leaderboard Data Available!!!") return end local t = {} for i,k in pairs (Leaderboard\_Data[w] or {}) do table.insert(t,k.playerID) end local playernamestbl = game\_network.request("loadPlayers", { playerIDs = t, listener = gamenetwork\_callback } ) for i,k in pairs (playernamestbl or {}) do Leaderboard\_Names[w][k.playerID] = k.alias end end end

t is nil and I never get to see the custom leaderboard i made… Any suggestions or problems I may be having? I’ve been checking my code over and over again for days now.

UPDATE: I call my leaderboard function after this, so I will see the leaderboard if there is data in the global ‘Leaderboard_Names’ array.

Is this block of code outputting anything?

 for i,k in pairs (d or {}) do print(i,k) end

t is going to be nil because game_network.request() doesn’t return anything. It’s an asynchronous call which means it runs in the background instead of blocking your app while it runs. You have to do the work to display your leaderboard’s data in the listener function where you have that block of code I posted above.

Rob

Thanks for the response Rob, and thanks for the explanation, i have fixed everything and it all makes more sense now.

I had changed everything and i use this to print:

 local t = event.data for i,k in pairs (t) do print(i,k) if type(k) == "table" then for e,r in pairs (k) do print(e,r) end end end

It is only printing out the indice names such as “playerID” and “value” but I dont see any actually values in the output? Shouldn’t i see “playerID” “G:1337” or “value” “50” or something like that in the output?

UPDATE: wait i think i found an error in the way i manipulated my print function

OKAY I fixed it up, something is wrong with my leaderboard code now, thanks for all the help!

You should. I would try:

print( json.prettify( event.data ) )

You will of course have to require json and see what that outputs.

Rob

Is this block of code outputting anything?

 for i,k in pairs (d or {}) do print(i,k) end

t is going to be nil because game_network.request() doesn’t return anything. It’s an asynchronous call which means it runs in the background instead of blocking your app while it runs. You have to do the work to display your leaderboard’s data in the listener function where you have that block of code I posted above.

Rob

Thanks for the response Rob, and thanks for the explanation, i have fixed everything and it all makes more sense now.

I had changed everything and i use this to print:

 local t = event.data for i,k in pairs (t) do print(i,k) if type(k) == "table" then for e,r in pairs (k) do print(e,r) end end end

It is only printing out the indice names such as “playerID” and “value” but I dont see any actually values in the output? Shouldn’t i see “playerID” “G:1337” or “value” “50” or something like that in the output?

UPDATE: wait i think i found an error in the way i manipulated my print function

OKAY I fixed it up, something is wrong with my leaderboard code now, thanks for all the help!

You should. I would try:

print( json.prettify( event.data ) )

You will of course have to require json and see what that outputs.

Rob