Sign In Register

How can we help you today?

Start a new topic

problem with Overwriting data

Good day.

I have an issue with overwriting data. It is not overwriting correclty and I cannot understand why it happens.

I will try to explain in steps:

1. At first I do create match between 2 players. As soon as match created, method OnMatchFoundMessage create data for that match.   

//OnMatchFountMessage script
var matchId = Spark.getData().matchId;
var matchData = Spark.getMultiplayer().loadMatch(matchId);

var participants = matchData.getParticipants();
var participantsData = [];

for(var i = 0; i < participants.length;i++){
    var characters = participants[i].getPlayer().getScriptData("characters");
    var chosenCharacter = characters.filter(function(character){
        return character.characterName == participants[i].getPlayer().getScriptData("choiseCharacterName") ? character : null;
    })[0];
    participantsData.push({
        playerID: participants[i].getPlayer().getPlayerId(),
        playerName: participants[i].getPlayer().getDisplayName(),
        strength:   chosenCharacter.strength,
        agility: chosenCharacter.agility,
        endurance: chosenCharacter.endurance,
        armor: chosenCharacter.armor,
        intellect: chosenCharacter.intellect,
        heals: 100,
        mana: 1,
        damage: 5,
        blockPoint: 1,
        attackPoint: 1
   });
 }
matchData.setMatchData({"participants":participantsData});
var mD = matchData.getMatchData();

  2. After that, players get connected to the session. As soon as both payers connected, server send them message to allow to enter game scene. 

//Real Time script
RTSession.onPlayerConnect(function(player){
    if(RTSession.getPlayers().length == MAX_PLAYER_COUNT)
    {
        RTSession.getLogger().debug(RTSession.getSessionId());
        playerID = player.getPlayerId();
        RTSession.newRequest().createMatchDetailsRequest()
        .setMatchId(RTSession.getSessionId())
        .setPlayerId(player.getPlayerId())
        .setRealtimeEnabled(true)
        .send(function(response){
            matchData = response.matchData;
            if (matchData) {
                matchID = response.matchId;
                RTSession.getLogger().debug(matchID);
                startGame();
            }
        });
    }
});

function startGame(){
    var rtData = RTSession.newData().setString(1, RTSession.getPlayers().length);
    RTSession.newPacket().setOpCode(6).setData(rtData).send();
}

When both players entered the game scene, they send message to server, confirming to start the game. Server begin to create data as soon as it gets messages from both players.

//Real Time script
RTSession.onPacket(200, function(packet){
    playerCounter();
    return false;
});

function playerCounter(){
    playerCount++;
    if(playerCount == 2){
        playerCount = 0;
        getMatchDetails();
    }
}

3. Data generated in real time script. As soon as data generated, real time script create request .createLogEventRequest().setEventKey("SET_MD") and send generated data to SET_MD 

//Real Time script
function getMatchDetails(){
    generateBattleStatistics(matchData);
    if(!isUseSkill)
    {
        RTSession.setTimeout(getMatchDetails, 20000);
    }
}

function generateBattleStatistics(matchData){
    var rtData = RTSession.newData().setString(1, "asfasf");
    RTSession.newPacket().setOpCode(7).setData(rtData).send();
    var participantData = [];
    for(var i = 0; i < RTSession.getPlayers().length; i++)
    {
        participantData.push({
            heals:  Math.round(matchData.participants[i].endurance * 200),
            damage: matchData.participants[i].strength * 10,
            mana: matchData.participants[i].intellect * 20,
            blockPoint: getRandomPoint(0,3),
            attackPoint: getRandomPoint(0,3)
        });
    }
    var request = RTSession.newRequest()
        .createLogEventRequest()
        .setEventKey("SET_MD");
    request.setmid(matchID);
    request.setpdata(participantData);
    request.setPlayerId(playerID)
        .send(function(response){
            if (!response.error) {
                RTSession.getLogger().debug(response);
                sendStatistics();
            } else {
                RTSession.getLogger().debug(response.error);
            }
    });
}

  4. Script SET_MD get data from createLogEventRequest()  

  

// Event script "SET_MD"
var matchID = Spark.getData().mid;
var scriptMatchData = null;
var participantsData = Spark.getData().pdata;
var matchParticipants = null;

Spark.getLog().debug(matchID);

var request = new SparkRequests.MatchDetailsRequest();
request.matchId = matchID;
request.realtimeEnabled = true;
var response = request.Send();

Spark.getLog().debug(participantsData);

scriptMatchData = response.matchData;


5. After that I'm trying to find a match and rewrite match’s data.

// Event script "SET_MD"
var match = Spark.getMultiplayer().loadMatch(response.matchId);
Spark.getLog().debug(match.getParticipants());
Spark.getLog().debug(match.getMatchData());
matchParticipants = scriptMatchData.participants;
Spark.getLog().debug(matchParticipants);

for(var i = 0; i < participantsData.length; i++)
{
    matchParticipants[i].heals = participantsData[i].heals;
    matchParticipants[i].mana = participantsData[i].mana;
    matchParticipants[i].damage = participantsData[i].damage;
    matchParticipants[i].blockPoint = participantsData[i].blockPoint;
    matchParticipants[i].attackPoint = participantsData[i].attackPoint;
}

match.setMatchData({"participants": matchParticipants});

 6. After rewriting, server send message to players that they can take new data and use it in game.  

//Real Time script
function sendStatistics() {
    var rtDataToSend = RTSession.newData().setString(1, "true");
    RTSession.newPacket().setOpCode(5).setData(rtDataToSend).send();
}

However, in reality data is not overwriten properly. I have three possible outcomes.

1. Data is not overwriten for both players.

2. Data is overwriten for one player.

3. Data successfully overwriten for both players.

I tried to check code in Test Harness and it is working correctly.

Could you please help me to solve this problem.  I need it to be overwriten for both players.

Thanks in advance


1 Comment

Hi Vitaly,


I can see that an agent is looking into this issue for you in the ticketing system. We are awaiting your response there.


Regards,

Liam

Login to post a comment