Error Create Leaderboard Authoritative

Hi,
I tried creating an Authoritative Leaderboard according to the instructions but I can’t? It always gives an error:
"rpc error: code = Internal desc = TypeError: Cannot read property 'DESCENDING' of undefined at writeLeaderboard (index.js:34:29(12))"

I code in index.js but not in typescript, so I can’t find nkruntime according to the instructions.
Can someone check for me?
Here is the instruction code:

let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
let authoritative = true;
let sort = nkruntime.SortOrder.DESCENDING;
let operator = nkruntime.Operator.BEST;
let reset = '0 0 * * 1';

let metadata = {
  weatherConditions: 'rain',
};

try {
    nk.leaderboardCreate(id, authoritative, sort, operator, reset, metadata);
} catch(error) {
    // Handle error
}

Below is the code in my index.js. nkruntime or nk both report errors.

let writeLeaderboard = function (ctx, logger, nk, payload)
{
    logger.info('leaderboardCreate called');

    let id = '4ec4f126-3f9d-11e7-84ef-b7c182b36521';
    let authoritative = true;
    let sort = nk.SortOrder.DESCENDING;
    let operator = nk.Operator.BEST;
    let reset = '0 0 * * 1';

    let metadata = {
        weatherConditions: 'rain',
    };

    let result;

    try {
        result = nk.leaderboardCreate(id, authoritative, sort, operator, reset, metadata);
    } catch(error) {
        return JSON.stringify({ code: 0, status: "BadRequest", data: error });
    }

    return JSON.stringify({ code: 1, status: "OK", data: result });
};

Hello @dhforever,

The issue is that nkruntime.Operator.BEST; doesn’t get resolved in the output code, I’m not sure why the TS compiler doesn’t make it part of the bundled file, we’ll try to resolve it, in the meantime redefining these values as consts in your own source code and referencing those should resolve the issue.

Hope this helps.

I look forward to receiving feedback on bug fixes soon. Sir

Sorry. Is there any way I can create an Authoritative Leaderboard with index.js? I run nakama with a windows installation, not docker. So the module runs with index.js file and not typescript.
Thank you.

@dhforever Nakama only supports JavaScript, so it never takes in TS code directly, however we have TS types and some examples on how to transpile TS to Nakama compatible JS code. I’d recommend you look into using TS if you aren’t, as it makes development much easier.

Yes, you can create an authoritative leaderboard, this is the TS function reference, but the signature will be the same: Function Reference - Heroic Labs Documentation.

Hope this helps.

1 Like