GameCenter Help

Hey again I need help for GameCenter. Ok I know how to enabled GameCenter to my game and look at the leaderboard. But every time I finish a game the High Score displays on the Screen. But it does not display on the Gamecenter leader Board this is how I display my high score.

[code] local scores = ice:loadBox( “scores” )
local high3 = scores:retrieve(“best3”)
print(high)
local score = 0
local time = 200

local highText = display.newText("", 0,0,“Arial”,22)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/3
highText:setTextColor( 0,0,0 )
local highScore = scores:retrieve(“best3”)
if highScore ~= nil then
highText.text = "HighScore: "… scores:retrieve(“best3”)
end

local function show_highScore()
gameOver = not gameOver
scores:storeIfHigher( “best3”, score )
scores:save()
local highText = display.newText("", 0,0,“Arial”,22)
highText.x = display.contentWidth/2
highText.y = display.contentHeight/2
highText:setTextColor( 0,0,0 )
if score > high3 then
if score > scores:retrieve(“best3”) then
highText.text = "New HighScore: "… scores:retrieve(“best3”)
print(“new high score”)
else
highText.text = "New HighScore: "… scores:retrieve(“best3”)
end
end
end
timer.performWithDelay(time, show_highScore, 1)[/code]

That how I display the High Score on the screen.

function updateHighScore(board, score) if gamenetworkEnabled == true then gameNetwork.request("setHighScore", { localPlayerScore={ value=tonumber(high3), category=board }}) end end gameover:addEventListener ("touch", updateHighScore)

Now This code above is suppose to post my highscore for GameCenter I think. So can anyone help me how to post score to gamecenter.

Help is appreciated thanks

:slight_smile: [import]uid: 17058 topic_id: 20508 reply_id: 320508[/import]

I’m not sure I would put the setting of the high score on a button asking the player to set the score. You should do that automatically and provide a button to show the leader board or fetch the scores and show them yourself.

[import]uid: 19626 topic_id: 20508 reply_id: 80410[/import]

@robmiracle so your saying I should set a timer to provide the high score to display on the Leaderboard right. Also is this set correct for it display for gamecenter or what should I change

function updateHighScore(board, score) if gamenetworkEnabled == true then gameNetwork.request("setHighScore", { localPlayerScore={ value=tonumber(high3), category=board }}) end end gameover:addEventListener ("touch", updateHighScore) [import]uid: 17058 topic_id: 20508 reply_id: 80418[/import]

No it should go inside your code when you know the game is over and you want to save the high score. Perhaps here:

function updateHighScore(board, score)  
 if gamenetworkEnabled == true then  
 gameNetwork.request("setHighScore", { localPlayerScore={ value=tonumber(high3), category=board }})  
 end  
end  
  
local function show\_highScore()   
 gameOver = not gameOver  
 scores:storeIfHigher( "best3", score )  
 scores:save()  
 local highText = display.newText("", 0,0,"Arial",22)  
 highText.x = display.contentWidth/2  
 highText.y = display.contentHeight/2  
 highText:setTextColor( 0,0,0 )  
 if score \> high3 then  
 if score \> scores:retrieve("best3") then  
 highText.text = "New HighScore: ".. scores:retrieve("best3")  
 print("new high score")  
 else  
 highText.text = "New HighScore: ".. scores:retrieve("best3")  
 end  
 updateHighScore("yourboardid", score)  
 end  
end  

[import]uid: 19626 topic_id: 20508 reply_id: 80432[/import]

As a side note to help you out:

gameover:addEventListener ("touch", updateHighScore)  

When that event listener calls updateHighScore, it passes one parameter to it, an event table that has various event parameters like the X and Y of where the user touched, if their finger is still down, moving, or picked up and the object the event listener is attached to.

This looks like you have a button named “gameover” that the player is to touch to end the game, is that true?

Anyway back to the event listener… The function called, in this case “updateHighScore” will only receive that one parameter. In side your definition of updateHighScore, you’re naming that event parameter “board”. The Parameter “score” will be nil. Since “board” is a table, its not the data you want to send to game Center. So your event handler simply wont work.

Looking at your example, if you do have a “gameover” button that the player taps, I would change your event handler to be:

gameover:addEventListener (“tap”, show_highScore)

I’m suggesting “tap” instead of “touch” because if you use “touch” the show_highscores will be called at least twice (began and ended) and if there is any movement, it could get called even more and we don’t have the code in show_highScore to absorb the events triggered by “touch”.
[import]uid: 19626 topic_id: 20508 reply_id: 80434[/import]

@robmiracle no the gameover is just I was testing sorry if you look at my code I display the High score with actually

 timer.performWithDelay(time, show\_highScore, 1) 

So I should you this instead.
The gameover basically I added for fun to these if it was working sorry for confusion [import]uid: 17058 topic_id: 20508 reply_id: 80437[/import]

@robmiracle you know I will just wait for the stable release for GameCenter. But thanks for the help

:slight_smile: [import]uid: 17058 topic_id: 20508 reply_id: 80444[/import]