Posting to Gamecenter

Gamecenter is successfully initiated, however the score will not post.

First, _G.score exists, i promise. Everything is set up in itunes connect, the only problem is posting the score. Thanks!
[lua]local gameNetwork = require “gameNetwork”
local function initCallback( event )
if event.data then
loggedIntoGC = true
native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )
else
loggedIntoGC = false
native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )
end
end
gameNetwork.init( “gamecenter”, initCallback )
if loggedIntoGC == true then
local function requestCallback( event )

end
gameNetwork.request( “setHighScore”,
{
localPlayerScore = { category=“com.boltvisual.L.arts”, value= _G.score },
listener=requestCallback
})
end[/lua]

Thanks again! [import]uid: 59735 topic_id: 22334 reply_id: 322334[/import]

I’m a little thrown off by your “ifs” and “ends” here.

It doesn’t look as though line 16 is within a function.

Is this throwing any errors when called?

Have you tried prints statements to debug? (Such as a print statement right before setting the highscore?) [import]uid: 52491 topic_id: 22334 reply_id: 89008[/import]

Only thing I can think of is changing it to this:

local function requestCallback( event )  
 if event.data then  
 native.showAlert( "Success!", "", { "OK" } )  
 end  
end  
  
if loggedIntoGC then   
 gameNetwork.request( "setHighScore",   
 {   
 localPlayerScore={ category="com.boltvisual.L.arts", value=\_G.score },  
 listener=requestCallback   
 })  
end  

Not fully sure if that will make a difference or not but thats how I have mine setup and it works. if thats not it, the only other thing I can think of is making sure your category spelling matches up with what you set in Connect. might of accidentally messed something up in one of them. [import]uid: 69700 topic_id: 22334 reply_id: 89018[/import]

So with my sandbox account, should the score be updating, because its not… [import]uid: 59735 topic_id: 22334 reply_id: 89080[/import]

so the logging in works, but the native alert for the event data does not…

[lua]local gameNetwork = require “gameNetwork”

local function all()
local function initCallback( event )
if event.data then
loggedIntoGC = true
native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )
else
loggedIntoGC = false
native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )
end
end

– function to listen for system events

if loggedIntoGC == false then
gameNetwork.init( “gamecenter”, initCallback )
end

local function requestCallback( event )
if event.data then
native.showAlert( “Success!”, “”, { “OK” } )
end
end

if loggedIntoGC then
gameNetwork.request( “setHighScore”,
{
localPlayerScore={ category=“com.boltvisual.L.arts”, value=_G.score },
listener=requestCallback
})
end
end
timer.performWithDelay(200, all, 1) [import]uid: 59735 topic_id: 22334 reply_id: 89081[/import]

Try a print after line 22 and 23 - do they both print? [import]uid: 52491 topic_id: 22334 reply_id: 89220[/import]

well game center only works on the device, can i print from there? [import]uid: 59735 topic_id: 22334 reply_id: 89227[/import]

okay, i got the native alert to print the score after it posts it from event.data. However, from the gameccenter app, i dont see the score increasing. Also, it only posts the first time? [import]uid: 59735 topic_id: 22334 reply_id: 89235[/import]

UPDATE: I figured out that at my menu scene, i was declaring loggedIntoGC false! All fixed. However, it still doesn’t update in the GC app…i am using a sandbox account. Is this normal? [import]uid: 59735 topic_id: 22334 reply_id: 89240[/import]

Just a question here… What is the point of wrapping all of that up into a function with a 2ms delay? Why not just leave it out of a function and it will trigger when that page is loaded into the app without any need for a timer and “all” function?

As far as the Sandbox/updating question, I’m not 100% on this one, but with my latest app which is the first time I’ve used GC, when I test on the iOS Simulator using the Sandbox account it doesn’t update any GC scores from my app when testing. But I released it using the same code that doesn’t update in the simulator and it all updates fine on the device to GC. [import]uid: 69700 topic_id: 22334 reply_id: 89247[/import]

A little late but yes, you can view print statements on device - just have it plugged into Xcode and view console :slight_smile: [import]uid: 52491 topic_id: 22334 reply_id: 89256[/import]

thank you!! [import]uid: 59735 topic_id: 22334 reply_id: 89289[/import]