That’s a good tip I never though of to see the output. It doesn’t always seem to print though, so I did start using native alerts with json.
Here’s the result from my post, which as far as I can tell seems successful:
{“provider”:“gamecenter”,“type”:“setHighScore”,“name”:“gameNetwork”,“data”:{“value”:41,“category”:“shipsLaunched”}}
Unfortunately when I do the loadScores call event.data is nil:
{“provider”:“gamecenter”,“type”:“loadScores”,“name”:“gameNetwork”}
On the iTunes Connect side, I’ve triple-checked that my leaderboard ID is shipsLaunched. My achievements are posting just fine, so I’m really quite lost here. I’ve even narrowed this down to a super-simple main.lua file that just logs me in, waits a few seconds, then posts a score and tries to load the scores. I’ve tried changing the leaderboard that I load, and if I do something other than shipsLaunched, it complains about a bad value, but I switch it back to shipsLaunched and just get the results above.
Here’s what I’m trying. I’ve run this with both of my two test user accounts from iTunes Connect in sandbox mode on my device.
[lua]local json = require “json”
gameNetwork = require “gameNetwork”
loggedIntoGC = false
local function initCallback(event)
if event.data then
loggedIntoGC = true
print(“Logged into Game Center”)
else
print(“Failed to log in to Game Center”)
end
end
function onSystemEvent(event)
if “applicationStart” == event.type then
loggedIntoGC = false
gameNetwork.init(“gamecenter”, { listener=initCallback })
return true
end
end
local function postScoreCallback(event)
print(“postScoreCallback”)
local data = json.encode(event)
native.showAlert(“postScoreCallback”, data, {“OK”})
end
local function postScore()
print(“postScore”)
gameNetwork.request(“setHighScore”, {
localPlayerScore = {
category=“shipsLaunched”,
value=10
},
listener = postScoreCallback
})
end
local function requestScoreCallback(event)
print(“requestScoreCallback”)
local data = json.encode(event)
native.showAlert(“requestScoreCallback”, data, {“OK”})
end
local function checkScore()
print(“checkScore”)
gameNetwork.request(“loadScores”, {
leaderboard = {
category = “shipsLaunched”,
playerScope = “Global”,
timeScope = “AllTime”,
range = {1,2}
},
listener=requestScoreCallback
})
end
Runtime:addEventListener(“system”, onSystemEvent)
timer.performWithDelay(10000, function()
postScore()
checkScore()
end
)[/lua]
[import]uid: 135199 topic_id: 25565 reply_id: 107622[/import]