Can someone show me how to implement leaderboard with corona cloud? any tutorial?

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 :slight_smile: 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 )