Issue with empty highscore table #13

Open
opened 2015-07-21 11:06:22 +00:00 by Dfacc · 6 comments
Dfacc commented 2015-07-21 11:06:22 +00:00 (Migrated from github.com)

Hello, have had problems when trying to fetchScores when the table is empty. Did this to try to fix it, think it works.
if f then
f[k] = v
end

Hello, have had problems when trying to fetchScores when the table is empty. Did this to try to fix it, think it works. if f then f[k] = v end
Dfacc commented 2015-07-21 12:25:30 +00:00 (Migrated from github.com)

did not work. I'm confused, i'm trying to get all scores for a highscore table and I'm only getting from users. Shouldn't I use fetchScores?

did not work. I'm confused, i'm trying to get all scores for a highscore table and I'm only getting from users. Shouldn't I use fetchScores?
pablomayobre commented 2015-07-21 17:51:22 +00:00 (Migrated from github.com)

This is what is going on in here:

Fetch score passes the username and token if tableID is not specified, this means that if you want data from the global table you only get data for the authenticated user, since the user has no data in the table the returned table is empty. There is a hackish fix for this:

GJ.fetchScores(nil, "")

This will pass the if tableID then conditional and ignore the authenticated user.

There is a problem with the function any way, because user data cannot be passed when providing a table ID. This could be fixed with something like:

function GJ.fetchScores(limit, tableID, userdata)
    local pu, pt, s = userdata, userdata, ""
    if tableID then s = "&table_id=" .. escape(tableID) end

    local d = req("scores/?limit=" .. (tonumber(limit or "") or 10) .. s, "keypair", pu, pt)
    local t, f = {}

    parseKeypair(d, function(k, v)
        if k ~= "success" then
            if k == "score" then
                f = {}
                table.insert(t, f)
            end
            f[k] = v
        end
    end)
    return t
end
This is what is going on in here: Fetch score passes the username and token if tableID is not specified, this means that if you want data from the global table you only get data for the authenticated user, since the user has no data in the table the returned table is empty. There is a hackish fix for this: ``` lua GJ.fetchScores(nil, "") ``` This will pass the if tableID then conditional and ignore the authenticated user. There is a problem with the function any way, because user data cannot be passed when providing a table ID. This could be fixed with something like: ``` lua function GJ.fetchScores(limit, tableID, userdata) local pu, pt, s = userdata, userdata, "" if tableID then s = "&table_id=" .. escape(tableID) end local d = req("scores/?limit=" .. (tonumber(limit or "") or 10) .. s, "keypair", pu, pt) local t, f = {} parseKeypair(d, function(k, v) if k ~= "success" then if k == "score" then f = {} table.insert(t, f) end f[k] = v end end) return t end ```
Dfacc commented 2015-07-23 14:46:12 +00:00 (Migrated from github.com)

Ok, I got it now thanks for the help :)

Ok, I got it now thanks for the help :)
pablomayobre commented 2015-07-23 22:05:06 +00:00 (Migrated from github.com)

Can you report back if the hack works? Even then dont close this issue since it still needs to be fixed, lets wait to see what @insweater has to say about this 😃

Can you report back if the hack works? Even then dont close this issue since it still needs to be fixed, lets wait to see what @insweater has to say about this :smiley:
mbrovko commented 2015-07-27 16:17:14 +00:00 (Migrated from github.com)

Sorry for the late response.

Yeah, it seems to be the problem. If code by @Positive07 worked for you, please let us know so we can push it to master branch.

Sorry for the late response. Yeah, it seems to be the problem. If code by @Positive07 worked for you, please let us know so we can push it to master branch.
pablomayobre commented 2015-07-27 17:50:00 +00:00 (Migrated from github.com)

Yeah! The later one, not the hack. Sorry, I cant test this (at least now) so your feedback will be appreciated @Dreanh

Yeah! The later one, not the hack. Sorry, I cant test this (at least now) so your feedback will be appreciated @Dreanh
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: library-mirrors/gamejoltlua#13
No description provided.