kumakore / kumakore-sdk

Kumakore SDK
http://www.kumakore.com
3 stars 0 forks source link

Unity: Calling Match.GetMoves(0) Multiple Times Produces Duplicates #52

Open blindgoat opened 10 years ago

blindgoat commented 10 years ago

I'm using Unity API vs 0.7.1

I have a match with five moves and the moveNum is 4. If I call match.getMoves(0) once and wait for the response, match.getMoves().Count == 5. If I call match.getMoves(0) again and wait for the response, match.getMoves().Count == 10. It duplicates the data in the moves list so entry 0 and 5 are the same, 1 and 6, etc.

I realize we should cache the info and not call getMoves again, but the issue shouldn't happen regardless. I fixed it with one line just comparing match.getMoveNum >= (match.getMoves().Count+1). Is there any reason this check can't be added to the API so it doesn't make a request to the server if the check is true?

Here's an example you can run to see. Replace this function in MatchListScene.cs of the MatchList demo to make it request the moves twice in a row.

public void GetMatchStatus(OpenMatch m) {
        match = m;
        match.getStatus().async (delegate(ActionMatchGetStatus action) {
            if(action.getCode () == StatusCodes.SUCCESS) {
                match = app.getUser ().getOpenMatches()[match.getMatchId()];
                message = "Match selected: " + match.getMatchId();
                userId = app.getUser ().getId ();
                matchLoaded = true;
                // load MatchInfo now
                // START my changes
                match.getMoves(0).async(delegate(ActionMatchGetMoves movesAction)
                {
                    Debug.Log("#1: moveNum="+match.getMoveNum()+"  numMoves="+match.getMoves().Count);

                    match.getMoves(0).async(delegate(ActionMatchGetMoves movesAction2)
                    {
                        Debug.Log("#2: moveNum=" + match.getMoveNum() + "  numMoves=" + match.getMoves().Count);
                    });
                });
                // END my changes
            } else message = "Error while loading match: " + action.getStatusMessage();
            if(match.getNudged()) message = match.getOpponentUsername() + " has nudged you!";
            //kumakore.user ().inventory().get ().async (GetInventoryDelegate);
        });
    }