gameNetwork.request("setHighScore") does not work on iOS. GameCenter bug?

Hi @Wiler Jr,

I just checked out the bug report. Is there any way you can submit another sample project that clearly shows this issue occurring, and doesn’t rely on any reading of strings from a “bestscore.txt” or otherwise? Basically, to fully diagnose this issue, we’d like to see your code simplified and tuned down to the core problem that you’re reporting.

Thanks,

Brent

I’ve just sent the code within a .rar to the same e-mail I received from Corona Support.

I’ve removed the loggedIntoGC variable and, for the “bestscore.txt” issue, I’ve put an instruction about changing the variable manually to a higher value after submitting the previous one and then be sent again.

There’s nothing more I can change besides the loggedIntoGC and the instruction to what to do, for it’s the almost same code I use to submit the highscores and open the leaderboards right afterwards. The difference between it and my real code lies on the finalScore that has to be changed manually instead of the one the player scores and is stored within the “bestscore.txt” file and on the matter that I don’t specify my leaderboard ID once you don’t have my game’s CFBundleIdentifier and .mobileprovision file generated by Apple (and I think you don’t even need it if it’s a Corona bug, right?).

Note: GPGS presents no problem concerning the submission of scores stored within “bestscore.txt” file.

Hi @Wiler Jr,

I’m looking at your code now, and I still don’t see how you’re ever submitting a “higher score”. You basically initialize GC, you submit a high score of 50, and that’s it… you never submit anything higher than 50, so the expected behavior is that GC does nothing beyond this.

Also, are you sure that “event.data” is true within your “initCallback()” listener function?

I’m currently doing a little of my own testing on GC using my own code, and I’ll let you know if I can diagnose anything related to your issue.

Thanks,

Brent

Within the code of my game, the “bestscore.txt” stored score is changed whenever the player scores a higher one. In the instructions within the last code I sent, I suggest changing the value 50 to a higher one after submitting it to see whether it works or not.

Hi @Wiler Jr,

Does your code work when you test it in the Game Center “sandbox” mode? In my testing, updating scores through the sandbox mode works perfectly, and I can see them instantly updating as I submit higher scores.

Brent

Yes, @Brent. We are testing in the Game Center with “sandbox mode” enabled. May I see the code you’re using? I think @torbenratzlaff might be in need of it as well.

Hi @Wiler Jr,

I did some more testing and everything seems to be working for me. I set up a very basic increment of a score which is assigned to a Composer variable (so basically, it’s just known throughout my code because it’s part of the core Composer table). This simply uses a standard button – widget.newButton() or whatever you want – to increment the score by 25 on each tap. When I do this, I’m seeing the result update instantly in Game Center, and it shows in the Sandbox leaderboard.

[lua]

local composer = require( “composer” )

– Create a Composer variable named “currentScore” with value of 0

composer.setVariable( “currentScore”, 0 )

– Listener function for submission of high score

local function setHighScoreListener( event )

    print(“setHighScore-----------------------------------------------------------”)

    print_r( event )

end

– Button handler function

local function handleButton( event )

    – Increment “currentScore” by 25

    composer.setVariable( “currentScore”, composer.getVariable( “currentScore” ) + 25 )

    – Submit new “currentScore” to Game Center leaderboard with ID of “1” in iTunes Connect

    gameNetwork.request( “setHighScore”,

        {

            localPlayerScore = { category=“1”, value=composer.getVariable( “currentScore” ) },

            listener = setHighScoreListener

        }

    )

end

[/lua]

A few notes:

  1. For “localPlayerScore”, the “category” of “1” is my leaderboard ID within iTunes Connect. Obviously this should be a more descriptive name, but I’m using that for testing.

  2. In the “setHighScoreListener()” function, the “print_r” function refers to that shown in the tutorial on printing table contents. I really suggest you use this, as it will dig deep down into a table and all of its sub-tables to show you the values, and that’s especially important for things like Game Center where tables usually have various child tables, and values within those tables which you’ll need to check. LINK: http://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/

So, please see if your code compares to this. It’s really simple and it works fine for me.

Thanks,

Brent

There goes the code I tested.

function new() local widget = require("widget"); local gc = require("gameNetwork"); local localGroup = display.newGroup(); local function onSystemEvent( event )     if(event.type == "applicationStart") then        gc.init("gamecenter");        return true    end end Runtime:addEventListener( "system", onSystemEvent ) local composer = require( "composer" ) -- Create a Composer variable named "currentScore" with value of 0 composer.setVariable( "currentScore", 0 ) local text = display.newText("0", 0, 0, native.systemFontBold, 20); localGroup:insert(text); local function showLeaderboards() gc.show("leaderboards", { leaderboard= {category="winners", timeScope="AllTime" }}); end -- Listener function for submission of high score local function setHighScoreListener( event )    print("setHighScore-----------------------------------------------------------")    print\_r(event) end -- Button handler function local function handleButton( event )    -- Increment "currentScore" by 25    text.text = composer.getVariable( "currentScore" ) + 25;    composer.setVariable( "currentScore", composer.getVariable( "currentScore" ) + 25 )    -- Submit new "currentScore" to Game Center leaderboard with ID of "1" in iTunes Connect    gc.request( "setHighScore",        {            localPlayerScore = { category="winners", value=composer.getVariable( "currentScore" ) },            listener = setHighScoreListener        }    ) end local leaderboardId = "winners"; gc.init("gamecenter"); local square = widget.newButton{ defaultFile = "square\_1.png", overFile = "square\_1-over.png", width = 64, height = 64, onRelease = handleButton } square.x, square.y = \_W\*0.5, \_H\*0.5; localGroup:insert(square); local leaderboard = widget.newButton{ defaultFile = "leaderboard.png", overFile = "leaderboard-over.png", width = 92, height = 46, onRelease = showLeaderboards } leaderboard.x, leaderboard.y = \_W\*0.5, \_H\*0.5 + leaderboard.height\*1.5; localGroup:insert(leaderboard); text.x, text.y = \_W\*0.5, square.y - text.height\*5; return localGroup; end

I submitted 50 as my first score. Afterwards, I scored 225, submitted it and the new score shown at the leaderboard was 25. Now, any other score I submit does not replace that last one. What an awkward issue!

Is there anything wrong with my code yet?

Hi Wiler Jr,

Can you go back and indent your code so it’s easier to read? It’s hard to follow what is nested within what.

Thanks,

Brent

I suggest you put some prints in your code to check your math.  The first time you call the touch handler, the score that will be set is 25.  You’re saved value in composer was 0. 0 + 25 is 25 and that’s what got set.

Rob

I hope it’s better expressed… 

local widget = require("widget"); local gc = require("gameNetwork"); local composer = require( "composer" ) local leaderboardId = "winners"; local square, leaderboard, text; local function onSystemEvent( event )      if(event.type == "applicationStart") then         gc.init("gamecenter");         return true     end end Runtime:addEventListener( "system", onSystemEvent ) composer.setVariable( "currentScore", 0 ) local function showLeaderboards() gc.show("leaderboards", {leaderboard= {category="winners", timeScope="AllTime"}}); end local function setHighScoreListener( event )     print("setHighScore-----------------------------------------------------------")     print\_r(event) end local function handleButton( event )     text.text = composer.getVariable( "currentScore" ) + 25;     composer.setVariable( "currentScore", composer.getVariable( "currentScore" ) + 25 )     gc.request( "setHighScore",         {             localPlayerScore = { category="winners", value=composer.getVariable( "currentScore" ) },             listener = setHighScoreListener         }     ) end gc.init("gamecenter"); square = widget.newButton{ defaultFile = "square.png",--any object overFile = "square-over.png",--any object label = "To Tap", width = 64, height = 64, onRelease = handleButton } square.x, square.y = \_W\*0.5, \_H\*0.5; leaderboard = widget.newButton{ defaultFile = "leaderboard.png",--any object overFile = "leaderboard-over.png",--any object label = "leaderboard", width = 92, height = 46, onRelease = showLeaderboards } leaderboard.x, leaderboard.y = \_W\*0.5, \_H\*0.5 + leaderboard.height\*1.5; text = display.newText("0", 0, 0, native.systemFontBold, 20); text.x, text.y = \_W\*0.5, \_W\*0.5 - text.height\*5;

Bob, regardless of it, the first submitted score 50 was overriden by 25. Besides, after the score “25” took place within the leaderboard, any higher value than that is not submitted.

I just have to ask the very obvious question.  Are you sure your leaderboard is setup right?  What you are describing is a setting where lower scores are better.

Rob

You touched the wound and I found it, Bob. A little mistake just the way you’ve suggested. I thought that wasn’t a configuration issue because @torbenratzlaff said he was getting the same issue even after being able to submit a score.

Thank you, Brent and Bob. And sorry for delaying the final solution to that issue for a lack of attention.

Hi Torben,

How are you testing? Can you list which 3 devices you’ve tested on, and which versions of iOS are installed on them?

Thanks,

Brent

Hi Brent,

I use a self scripted log window, which shows printed messages inside the app.

I use it to display the event returned to the request listener function.

Unfortunetly I wasn’t able to get the real device system log.

Curious thing is, that the listener function seems not to be called.

Testing devices are:

iPad Air

iPad mini

iPhone 4S

Which all use the latest iOS version. 8.1.2 I belive.

Hi @torbenratzlaff,

Have you enabled the GameCenter “sandbox” mode as described in this document?

http://docs.coronalabs.com/plugin/gameNetwork-apple/init.html

Brent

Hi Brent,

I’m not sure, have to check that.

I think it’s strange, that the achievements are working and the leaderboard not.

@Brent

I checked and I hab enabled the sandbox mode.

So that wasn’t the error.

Hi Torben,

Which is the bug you read about last September? Do you have a case # for that? Did anybody file an actual case for it?

Thanks,

Brent

Hi Brent,

I reffered to general issues with GameCenter, like this one in august last year:

http://forums.toucharcade.com/showthread.php?t=240331&page=3

Which had an official entry in the apple developer forums as well.

After all I’m a little desperate, that I’m not able to find the error.