The documentation about leaderboards is not in understandable format.
I want to code less, play more
thanks!
The documentation about leaderboards is not in understandable format.
I want to code less, play more
thanks!
Hi, I would check out this guide https://docs.coronalabs.com/guide/cloud/leaderachieve/index.html
Thanks
-Mohamed
Thank you, Mohamed!
I was trying to init game network, but Crona Simulator (on Windows and Mac) says “WARNING The ‘gameNetwork’ libruary is not available on this platform”. On device - lua error and so on.
CC\_Access\_Key = "mykey" CC\_Secret\_Key = "myseckey" coronaCloud = require ( "corona-cloud-core" ) coronaCloud.init( CC\_Access\_Key, CC\_Secret\_Key ) ----------------------------------------- --------------dashboard------------------- gameNetwork = require( "gameNetwork" ) local params = { accessKey = CC\_Access\_Key, secretKey = CC\_Secret\_Key, } gameNetwork.init( "corona", params ) -------------------------------------------
Hi,
Yes this was pulled from the build, we should be announcing something about this soon.
Although it is useful to use the gameNetwork lib for Corona Cloud as it provides you with pre-made UI. You can still create and use leaderboards without it.
-Mohamed
Ok, I read everything many-many times and I learned how to register account and login with it.
I did a little example with 2 buttons. First button submits score and the second button should be getting score and print it. (keys and leaderboardID was changed)
Simulator Output:
User is logged in : true
The user profile: {…}
score = nil
What is wrong? I can’t submit or get the score?
local cloud = require( "cloud" ) local json = require( "json" ) local CC\_Access\_Key = "1d3d8f6gg45dxxxxx6g6d5dbc20aef5xxxxx" local CC\_Secret\_Key = "d77d7f5fd6s7xxxxx56d5sd45d5f56fd7d7xxxxx" -------------------------- local authListener = function( event ) -- all events contain event.name, event.type, event.error, event.response. if event.type == "loggedIn" then print( "User is logged in: ", cloud.isLoggedIn ) -- get the user profile cloud.getProfile() end if event.type == "getProfile" then print( "The user profile: ", event.response ) end end --------------------------- cloud.init( CC\_Access\_Key, CC\_Secret\_Key, authListener ) --[[------------ local regParams = {} regParams.token = "CloudPlayer76" regParams.displayName = "CloudPlayer76" regParams.firstName = "John" regParams.lastName = "Smith" regParams.email = "smith@gmail.com" regParams.password = "zzzzzz" cloud.registerUser( regParams ) -----------]] local loginParams = {} loginParams.type = "user" loginParams.email = "smith@gmail.com" loginParams.password = "zzzzzz" cloud.login( loginParams ) local leaderboards = cloud.leaderboards ------- local function leaderboardsListener( event ) if ( event.type == "getScores" and event.error == nil ) then local results = event.results print ("score =",results) end end leaderboards.setListener( leaderboardsListener ) ------- local bt1\_score\_submit = display.newRect(100,100,100,100) local bt2\_score\_get = display.newRect(400,100,100,100) local myLeaderBoard = "5173dxxxxxxs7sd89f0001" local score =1000 local function ScoreSubmit() leaderboards.submitHighScore( myLeaderBoard, score ) end local function ScoreGet() leaderboards.getScores( myLeaderBoard) end bt1\_score\_submit:addEventListener("tap",ScoreSubmit) bt2\_score\_get:addEventListener("tap",ScoreGet)
Hi @nta84,
Unless I’m mistaken, it seems that you’re not handling the “submitHighScore” event type in your leaderboards listener. You send that event from your “ScoreSubmit()” function, but you don’t handle it in the listener, so the score is never submitted.
Hope this helps,
Brent
Actually it returns “event.response” which is a JSON string.
Try this:
[lua]
local function leaderboardsListener( event )
if ( event.type == “getScores” and event.error == nil ) then
local results = json.decode(event.response)
– you can use the print_r() function from community code to dump the table to see the values
end
end
[/lua]
Looks like I missed something updating that guide. Will get fixed.
Try this:
[lua]
local function leaderboardsListener( event )
if ( event.type == “getScores” and event.error == nil ) then
local results = json.decode(event.response)
for i = 1, #results do
print(i,results.username,results.value)
end
end
end
[/lua]
I have tried and results are nil
Simulator Output:
User is logged in : true
The user profile: {…}
1 nil nil
2 nil nil
What type of data the submitted score value should be? integer, string, or array?
local score = ? leaderboards.submitHighScore( myLeaderBoard, score )
Hi @nta84,
It should be in string format… is that what you tried? Or did you try both string and number with no success on either?
Brent
Why don’t you go to the community code and find the print_r() function and use that to dump the results table or print the event.response string to see the JSON encoded version and see what’s getting returned?
Thanks to everybody! I tried to submit number and string and it accept both number and string (string = “numbers”). Now with print_r() it’s clear that submitHighScore and getScores are working Why, I can’t get only results.value?
simulator output:
table: 126158F0 { [1] =\> table: 126158F0 { [updated\_at] =\> "2013-04-25T11:19:47+00:00" [username] =\> "CloudPlayer75" [\_id] =\> "5177xxxxxxxxxxxxxxxxxxx02" [value] =\> 13420 [leaderboard\_id] =\> "5173xxxxxxxxxxxxxxxxxx000001" [created\_at] =\> "2013-04-24T07:10:43+00:00" [user\_id] =\> "517xxxxxxxxxxxxxxxxxx001" } [2] =\> table: 126158F0{ [updated\_at] =\> "2013-04-25T04:51:33+00:00" [username] =\> "CloudPlayer76" [\_id] =\> "5178bxxxxxxxxxxxxxxxxxxx0001" [value] =\> 1000 [leaderboard\_id] =\> "51738xxxxxxxxxxxxxxxxxx0001" [created\_at] =\> "2013-04-25T04:51:33+00:00" [user\_id] =\> "5177xxxxxxxxxxxxxxxxxxxxxx001" } } 1 nil nil 2 nil nil
local function leaderboardsListener( event ) if ( event.type == "getScores" and event.error == nil ) then local scoreStrings = {} local results = json.decode(event.response) print\_r(results) for i = 1, #results do print(i,results.username,results.value) end end end leaderboards.setListener( leaderboardsListener )
Hi, I would check out this guide https://docs.coronalabs.com/guide/cloud/leaderachieve/index.html
Thanks
-Mohamed
Thank you, Mohamed!
I was trying to init game network, but Crona Simulator (on Windows and Mac) says “WARNING The ‘gameNetwork’ libruary is not available on this platform”. On device - lua error and so on.
CC\_Access\_Key = "mykey" CC\_Secret\_Key = "myseckey" coronaCloud = require ( "corona-cloud-core" ) coronaCloud.init( CC\_Access\_Key, CC\_Secret\_Key ) ----------------------------------------- --------------dashboard------------------- gameNetwork = require( "gameNetwork" ) local params = { accessKey = CC\_Access\_Key, secretKey = CC\_Secret\_Key, } gameNetwork.init( "corona", params ) -------------------------------------------
Hi,
Yes this was pulled from the build, we should be announcing something about this soon.
Although it is useful to use the gameNetwork lib for Corona Cloud as it provides you with pre-made UI. You can still create and use leaderboards without it.
-Mohamed
Ok, I read everything many-many times and I learned how to register account and login with it.
I did a little example with 2 buttons. First button submits score and the second button should be getting score and print it. (keys and leaderboardID was changed)
Simulator Output:
User is logged in : true
The user profile: {…}
score = nil
What is wrong? I can’t submit or get the score?
local cloud = require( "cloud" ) local json = require( "json" ) local CC\_Access\_Key = "1d3d8f6gg45dxxxxx6g6d5dbc20aef5xxxxx" local CC\_Secret\_Key = "d77d7f5fd6s7xxxxx56d5sd45d5f56fd7d7xxxxx" -------------------------- local authListener = function( event ) -- all events contain event.name, event.type, event.error, event.response. if event.type == "loggedIn" then print( "User is logged in: ", cloud.isLoggedIn ) -- get the user profile cloud.getProfile() end if event.type == "getProfile" then print( "The user profile: ", event.response ) end end --------------------------- cloud.init( CC\_Access\_Key, CC\_Secret\_Key, authListener ) --[[------------ local regParams = {} regParams.token = "CloudPlayer76" regParams.displayName = "CloudPlayer76" regParams.firstName = "John" regParams.lastName = "Smith" regParams.email = "smith@gmail.com" regParams.password = "zzzzzz" cloud.registerUser( regParams ) -----------]] local loginParams = {} loginParams.type = "user" loginParams.email = "smith@gmail.com" loginParams.password = "zzzzzz" cloud.login( loginParams ) local leaderboards = cloud.leaderboards ------- local function leaderboardsListener( event ) if ( event.type == "getScores" and event.error == nil ) then local results = event.results print ("score =",results) end end leaderboards.setListener( leaderboardsListener ) ------- local bt1\_score\_submit = display.newRect(100,100,100,100) local bt2\_score\_get = display.newRect(400,100,100,100) local myLeaderBoard = "5173dxxxxxxs7sd89f0001" local score =1000 local function ScoreSubmit() leaderboards.submitHighScore( myLeaderBoard, score ) end local function ScoreGet() leaderboards.getScores( myLeaderBoard) end bt1\_score\_submit:addEventListener("tap",ScoreSubmit) bt2\_score\_get:addEventListener("tap",ScoreGet)
Hi @nta84,
Unless I’m mistaken, it seems that you’re not handling the “submitHighScore” event type in your leaderboards listener. You send that event from your “ScoreSubmit()” function, but you don’t handle it in the listener, so the score is never submitted.
Hope this helps,
Brent
Actually it returns “event.response” which is a JSON string.
Try this:
[lua]
local function leaderboardsListener( event )
if ( event.type == “getScores” and event.error == nil ) then
local results = json.decode(event.response)
– you can use the print_r() function from community code to dump the table to see the values
end
end
[/lua]
Looks like I missed something updating that guide. Will get fixed.