Xcode gamecenter: calling specific leaderboard stops you from calling functions to the right of tab

Real head scratcher here. I’ve pushed several versions of my project to Xcode, and they’ve all worked really well. But then, I added support for gamecenter leaderboards (I’m pretty sure that’s the only change that I made), and I now find that the project throws a Codea runtime error whenever it tries to call a function that is in a tab to the right of the current tab. To test this I created a dummy function, called dummyfunc, which I call from setup() in Main.lua. When I place dummyfunc in a tab to the left of Main.lua (that is, above Main.lua in the “Buffer Order” array in Info.plist), dummyfunc gets called fine. But when I move the function to a file to the right/below of Main.lua I get attempt to call a nil value (global 'dummyfunc'). I get this in the simulator and when I deploy to device. It’s really strange. The only thing I can think that would produce this effect is if there were a call to setup() outside of any function, so that it is getting called before all the tabs have been read (I’ve checked my code to make sure there isn’t somehow an errant setup() call somewhere). Does this issue sound familiar to anyone? Any ideas what could be causing this?

Don’t happens for me :expressionless:

After retracing my steps I’ve worked out what causes the error but it’s a really strange one. If I have in my code gamecenter.submitScore or gamecenter.showLeaderboards with a specific leaderboard named, the error described above happens, regardless of whether or not these functions are called. (eg I have a “show leaderboards” button. The gamecenter.showLeaderboards command isn’t called until the button is pressed. But I’m getting this error regardless of whether the command is called) If I remove the leaderboard ID, so that I’m just submitting and showing the default leaderboard, the error doesn’t occur and everything works as it should.

But the question is, how could this be? Why would including a specific leaderboard ID in some code that isn’t being run cause the setup function to not be able to see functions to the right of Main.lua?

Just to reiterate, what causes the error is not whether the specific leaderboard function is called, but whether or not that line of code is commented out. I’ve never seen that kind of behaviour before.

I wonder whether it is connected to the unused variable 'weakSelf' warning that the gamecenter addon causes. I note that that warning relates to line 160, which is inside the function showLeaderboardWithID (ie with a specific ID).

So it seems we cannot have more than 1 leaderboard per app, as if you try to reference a specific leaderboard, you get this really bizarre error.

Anyone else able show or submit to a specific leaderboard (via its leaderboard iD)?

created an issue ticket here:

https://bitbucket.org/TwoLivesLeft/core/issues/393/gamecentersubmitscore-or-showleaderboard

@yojimbo2000 maybe I can help you

Did you create the leader board on iTunes connect?

Yes, the leaderboard is created on itunes connect. Currently it’s the only leaderboard for this particular app, so I guess that makes it the default leaderboard. Everything works fine, as long as I don’t give a leaderboard ID in either gamecenter.submitScore or gamecenter.showLeaderboards. It all seems to be working, the score I submit ends up on the leaderboard.

The app isn’t out yet, I’m testing the leaderboards using testflight.

But if I specify a leaderboard ID (if for instance, in future, I wanted to have more than one leaderboard) then, even if the code isn’t called, I get the weird error I describe above. So just uncommenting the line that includes the leaderboard ID is enough to produce the error, which I find really weird.

A few questions for you, @erickyamato , and anyone else using gamecenter. Do any of your apps have more than one leaderboard? Have you tried the commands with a leaderboardID? eg gamecenter.showLeaderboards("singlePlayerHighscores") or whatever your leaderboard is called? Do you get the unused variable 'weakSelf' warning being thrown by the gamecenter add-on?

Thanks!

@yojimbo2000 my leader board is single… The warning is not a problem, you can comment this line

The warning is not a problem, you can comment this line

Really, you can just comment out the whole line?

I’ll try that.

And do you use the leaderboard ID in the call to showLeaderboards?

Is there a game center command? / Now I understand why it didn’t work for me

I commented out the weakSelf line in the gamecenter addon, and that didn’t seem to cause any problems (though presumably that line is there for a reason?), but it doesn’t fix the issue. I can only access the default leaderboard. If I have a line of code referencing a leaderboard ID then I get the weird error described above, regardless of whether that code actually runs.

@yojimbo2000 no problems commenting this line… It is just a warning, not a error…

I put gamecenter.showLeaderboard(highscore, AmarganA), where highscore is a variable used in your code to store the high score values and AmarganA is the name of the leader board setted on iTunes Connect

@yojimbo2000 can I response you tomorrow?

I’ll see on my code