setPageOffset in Corona not working

0 votes

I am trying to create a relative leaderboard in Corona where the user will see his score and other people's around him. I am following suggestions from this thread to do it.

Whenever I attempt to use setPageOffset the function will not have any paging performed. Instead, it returns a list starting from Rank 1 and down (the regular resposne as if no paging was given).

The code I used is as follows:

local pagingOffset = 10
local limit = 5
local scoreBoardService = App42API.buildScoreBoardService()
scoreBoardService.setPageOffset(pagingOffset)
scoreBoardService.getTopNRankings(gameName, limit, App42CallBackMyRankList)

 

Could anyone shed light on this?

asked Oct 16, 2014 in App42 Cloud API-BaaS by thebattlebuddy (23 points)

1 Answer

0 votes

Hello,

Please replace the below line from this metaHeadersParams.pageOffset = pageOffset

to metaHeadersParams.offset = pageOffset in App42Service.lua file which is in App42-Lua-API folder. 

Please make these changes and let us know if it helps.

Himanshu Sharma

answered Oct 16, 2014 by hs00105 (2,005 points)
I have made the change in App42Service, but it did not appear to make any difference in the result object. It still returns from the highest score and down with no offset.
Could you please put a below lines of code before calling leader-board api and share the logs with us:

local App42Log = require("App42-Lua-API.App42Log")
App42Log:setDebug(true)

Thanks,
Himanshu Sharma
Sure thing. This is the response that is returned from debug. It is exactly the same response I would get from a normal request starting from rank 1 (aside form the signature).

    SignParams is : {"apiKey":"2105a43d6ffe1db332cf7d46107a122e436676f583373875cfac6
    7f4150757f1","max":5,"name":"Test1","sessionId":"3cc56a1c-1
    d69-4391-8dab-c8cbea3e333e","timeStamp":"2014-10-21T02:45:39.000Z","version":"1.
    0"}
    signature is : qUpbhqyh5sOxvteoqIwOjAfEnZ4%3D
    Header Key is : SDKName   Header Value is : "Corona"
    Header Key is : apiKey   Header Value is : "2105a43d6ffe1db332cf7d46107a122e4366
    76f583373875cfac67f4150757f1"
    Header Key is : dataACL   Header Value is : ""
    Header Key is : jsonObject   Header Value is : "[]"
    Header Key is : resource   Header Value is : "game/scoreboard"
    Header Key is : selectKeys   Header Value is : "[]"
    Header Key is : sessionId   Header Value is : "3cc56a1c-1d69-4391-8dab-c8cbea3e3
    33e"
    Header Key is : signature   Header Value is : "qUpbhqyh5sOxvteoqIwOjAfEnZ4%3D"
    Header Key is : timeStamp   Header Value is : "2014-10-21T02:45:39.000Z"
    Header Key is : version   Header Value is : "1.0"
    Request URI is : https://api.shephertz.com/cloud/1.0/game/scoreboard/Test1/ranking/5?
    Success is : {"app42":{"response":{"success":true,"games":{"game":{"name":"Doubl
    eDiamondCherriesTest1","scores":{"score":[{"userName":"UnknownUser-DDC01---ZGvm1
    PoV;Alp5c_","value":5619,"createdOn":"2014-10-12T02:07:27.000Z","scoreId":"Rt8X6
    ifrFU8jS07hv1y6fsIXkRM="},{"userName":"UnknownUser-DDC01---D0?D4=d35uoEktm","val
    ue":2204,"createdOn":"2014-10-12T04:22:05.000Z","scoreId":"FdQEA6bi+NOAdHTXpNxxM
    aKkQ="},{"userName":"UnknownUser-DDC01---><Q57fpe:25Gf>j","value":1161,"createdO
    n":"2014-10-12T23:43:22.000Z","scoreId":"Da3axraRV05F0hMNPeI+Jr6SA20="},{"userNa
    me":"UnknownUser-DDC01---3Gq7=b^C0zApWfT","value":1138,"createdOn":"2014-10-12T0
    4:16:41.000Z","scoreId":"+PJDyIkdjQct51ZIo+OKCBS0mcE="},{"userName":"UnknownUser
    -DDC01---^BldAlYQGb;9NH^","value":1060,"createdOn":"2014-09-28T20:38:50.000Z","s
    coreId":"teIS4wxD3ysctklvPfk2eVka48="}]}}}}}}
Thanks for sharing the logs details. Looks like your page offset is not set correctly in Leader-board call. Kindly use the below code snippet and let us know if it helps:

 
local gameName = "DoubleDiamondCherriesTest1"
local App42CallBack = {}
scoreBoardService:setPageOffset(3);
scoreBoardService:getTopRankings(gameName,App42CallBack)
function App42CallBack:onSuccess(object)
            print("Game name is "..object:getName())
            if table.getn(object:getScoreList()) > 1 then
                        for i=1,table.getn(object:getScoreList()) do
                                    print("userName is : "..object:getScoreList()[i]:getUserName())
                                    print("score is : "..object:getScoreList()[i]:getValue())
                        end
            else
                        print("userName is : "..object:getScoreList():getUserName())
                        print("score is : "..object:getScoreList():getValue())
            end
end
function App42CallBack:onException(exception)
            print("Message is : "..exception:getMessage())
            print("App Error code is : "..exception:getAppErrorCode())
            print("Http Error code is "..exception:getHttpErrorCode())
            print("Detail is : "..exception:getDetails())
end
 
Thanks,
Himanshu Sharma
The code I have is set up the same way as what you have provided. I ran a step-by-step debug and found that the value passed into setPageOffset() was somehow nil when it actually got into the function itself. If I add a random variable in as another parameter the offset works as expected.

scoreBoardService:setPageOffset(3); --passes in nil
scoreBoardService:setPageOffset("not used", 3); --passes in 3 as first parameter

I'm not able to explain this phenomenon, but it makes it work. This may be something further on my end which I will have to look into. Thank you for your support!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...