iOS Question Leaderboard playerScope

natesobol

Member
Licensed User
Hi, I have another question to do with gamecenter,

I am trying to have it so when the player clicks to open the leaderboard, they're brought to the "global" leaderboard instead of "friends".
92902.jpg
After doing some investigation, I found out that apple allows you to do this through playerScope.


When I set the playerScope field, it returns the correct value, in this following instance 1... But it wont correlate to the interface and will still display "friends" as the default.

My question is what am I doing wrong?

Code: Copy
    Dim gc As NativeObject
    gc = gc.Initialize("GKGameCenterViewController").RunMethod("new", Null)
    gc.SetField("leaderboardCategory", BoardId)
    gc.SetField("viewState", viewState)
    
    Dim ac As NativeObject
    ac = ac.Initialize("GKLeaderboard").RunMethod("new", Null)
    ac.SetField("playerScope", 1)
    Log(ac.GetField("playerScope"))

Thanks for any and all help
 
Erel here's what I have to bring up the leaderboard

Code: Copy
Sub ShowLeaderboard(Page As Page, BoardId As String, viewState As Int)
    Dim gc As NativeObject
    gc = gc.Initialize("GKGameCenterViewController").RunMethod("new", Null)
    gc.SetField("leaderboardCategory", BoardId)
    gc.SetField("viewState", viewState)
    
    Dim ac As NativeObject
    ac = ac.Initialize("GKLeaderboard").RunMethod("new", Null)
    ac.SetField("playerScope", 1)
    Log(ac.GetField("playerScope"))
    
    Dim del As NativeObject
    del = del.Initialize("B4IGameCenterViewControllerDelegate").RunMethod("new", Null)
    gc.SetField("gameCenterDelegate", del)
    
    Dim native As NativeObject = Page
    native.RunMethod("presentViewController:animated:completion:", Array(gc, True, Null))
End Sub

#if OBJC
@end
@interface B4IGameCenterViewControllerDelegate :NSObject<GKGameCenterControllerDelegate>
@end
@implementation B4IGameCenterViewControllerDelegate
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
   [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
#End If
 
Upvote 0
'ac' object isn't used. It doesn't do anything.

It should be something like:
Code: Copy
Dim LeaderboardId As String = "..."
Dim PlayerScore As Int = 0 '0 = global, 1 = friends only.
Dim TimeScope As Int = 0 '0 = Today, 1 = Week, 2 = AllTime
 Dim gc As NativeObject
gc = gc.Initialize("GKGameCenterViewController").RunMethod("alloc", Null)
gc.RunMethod("initWithLeaderboardID:playerScope:timeScope:", Array(LeaderboardId , PlayerScope, TimeScope))

 Dim del As NativeObject
    del = del.Initialize("B4IGameCenterViewControllerDelegate").RunMethod("new", Null)
    gc.SetField("gameCenterDelegate", del)
    
    Dim native As NativeObject = Page
    native.RunMethod("presentViewController:animated:completion:", Array(gc, True, Null))
End Sub
 
Upvote 0
Many thanks Erel, it worked.

I had tried to do something similar, but was bit confused when it came to initializing and the parameters.

This clears a lot of that up.
 
Upvote 0

Similar Threads

Back
Top