Accessing match properties in RPC functions


I refer to this ticket: Make a match with 1 player only

I open this new case as it is a separate issue from the original ticket.

I need to read the properties of the match object in an RPC function.

The complete code is follows:

function rpcLSfindOrCreateMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string
    let json = JSON.parse(payload);

    let limit = 10;
    let isAuthoritative = true;
    let label = json['aLabel'];
    let minSize = 0;
    let maxSize = 100;
    //let matches: nkruntime.Match[] = [];

    var matches = nk.matchList(limit, isAuthoritative, label, minSize, maxSize, "");

    // If matches exist, sort by match size and return the largest.
    let vIndex = -1;
    if (matches.length > 0)

        for (let vI = 0; vI < matches.length; vI++)
            if (matches[vI].label == label)
                vIndex = vI;

    if (vIndex > -1)
        logger.warn('Found existing match');
        return matches[vIndex].matchId;
        var matchId = nk.matchCreate("lobby", { "label": label });
        return JSON.stringify({ matchId });

When I try to compile this typescript code the compiler returns:

rpcLSfindOrCreateMatch.ts:21:29 - error TS2339: Property 'Label' does not exist on type 'Match'.

21             if (matches[vI].Label == label)

Is it possible that I’m wrong something like, for example, I don’t include definitions or anything else?

The property matchID is recognized but no LABEL.

What’s wrong?
thank you

Hello @solidsnakeit

The fix for the missing ‘label’ field on the Match structure has already landed (Add missing label to TS match definition. (#74) · heroiclabs/nakama-common@27fe749 · GitHub), so if you upgrade the package to the latest version/commit you should see it.

You may need to remove the package and reinstall it to see the effects of the fix.

YES! It works. Thank you very much. :slight_smile: