Sign In Register

How can we help you today?

Start a new topic

Problem witch Real-Time script

I send a packet with 7 code to clients in RTSession.onPlayerConnect . At first averything worked, bot through 2 hours the packets stopped working. RTSession.onPlayerConnecnt method not worked. Why? Please help me. I will be very grateful.

// ====================================================================================================
//
// Cloud Code for RT_TEST_RECIEVE, write your code here to customize the GameSparks platform.
//
// For details of the GameSparks Cloud Code API see https://docs.gamesparks.com/
//
// ====================================================================================================
var MAX_PLAYER_COUNT = 2;
RTSession.onPlayerConnect(function(player){
    var rtDataToSend = RTSession.newData().setString(1, "foo");
    RTSession.newPacket().setOpCode(7).setData(rtDataToSend);
    if(RTSession.getPlayers().length === 2){
        //getMatchDetails();
    }
});
function generateBattleStatistics(matchData){
    var participantData = [];
    for(var i = 0; i < matchData.participants.length; i++)
    {
        participantData.push({
            heals:  matchData.participants[i].endurance * 20,
            damage: matchData.participants[i].strength,
            blockPoint: getRandomPoint(0,3),
            attackPoint: getRandomPoint(0,3)
        });
    }
    var request = RTSession.newRequest().createLogEventRequest().setEventKey("SET_MD");
    request.setmid(RTSession.getSessionId());
    request.setpdata(participantData);
    request.setPlayerId(RTSession.getPlayers()[0].getPlayerId())
    .send();
}

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

function getMatchDetails(){
    RTSession.newRequest().createMatchDetailsRequest()
        .setMatchId(RTSession.getSessionId())
        .setPlayerId(RTSession.getPlayers()[0].getPlayerId())
        .send(function(response){
            var matchData = response.matchData;
            if (matchData) {
                generateBattleStatistics(matchData);
            } else {
                
            }
        });
    RTSession.setTimeout(getMatchDetails, 10000);
}

function getRandomNumber(min, max) {
  return Math.random() * (max - min) + min;
}

function getRandomPoint(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

  

1 Comment

Hi Vitaly,


Apologies for the delayed response here. Are you still having issues with this ? If so just let us know and we'll have someone take a look at this for you.


Regards,

Liam

Login to post a comment