In atributes (Events) I make variable type - json. If I want to receive data from json file - the data is null.
Here is the code:
//Sending data to json variable
//====================================================================================================
//
// 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 matchData;
var participantData = [];
RTSession.setInterval(function(){
getMatchDetails();
if(matchData != undefined)
{
generateBattleStatistics();
}
}, 10000);
function generateBattleStatistics(){
for(var i = 0; i < matchData.participants.length; i++)
{
participantData.push({
heals: matchData.participants[i].heals == null ? matchData.participants[i].endurance * getRandomNumber(20, 30) : matchData.participants[i].heals,
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.settest(JSON.stringify(participantData));
request.setPlayerId(RTSession.getPlayers()[0].getPlayerId())
.send(function(response){
sendStatistics();
});
}
function sendStatistics(){
var rtDataToSend = RTSession.newData().setString(1, "true");
RTSession.newPacket().setOpCode(5).setData(rtDataToSend).send();
}
//Receiving data from json variable ====================================================================================================
//
// Cloud Code for SET_MD, write your code here to customize the GameSparks platform.
//
// For details of the GameSparks Cloud Code API see https://docs.gamesparks.com/
//
// ====================================================================================================
var matchID = Spark.getData().mid;
var testJSON = JSON.parse(Spark.getData().test);
var matchDetails = Spark.getMultiplayer().loadMatch(matchID);
var matchData = matchDetails.getMatchData();
for(var i = 0; i < testJSON.length; i++)
{
matchData.participants[i].heals = testJSON[i].heals;
matchData.participants[i].damage = testJSON[i].damage;
matchData.participants[i].blockPoint = testJSON[i].blockPoint;
matchData.participants[i].attackPoint = testJSON[i].attackPoint;
}
matchDetails.setMatchData({"participants": matchData.participants});
Thanks in advance
Best Answer
V
Vitaly Evtukh
said
over 5 years ago
LOL. I already solved the problem. Result:
var matchID = Spark.getData().mid;
var participantsData = Spark.getData().pdata;
var matchDetails = Spark.getMultiplayer().loadMatch(matchID);
var newMatchData = matchDetails.getMatchData();
for(var i = 0; i < participantsData.length; i++)
{
newMatchData.participants[i].heals = participantsData[i].heals;
newMatchData.participants[i].damage = participantsData[i].damage;
newMatchData.participants[i].blockPoint = participantsData[i].blockPoint;
newMatchData.participants[i].attackPoint = participantsData[i].attackPoint;
}
matchDetails.setMatchData({"participants": newMatchData.participants});
1 Comment
V
Vitaly Evtukh
said
over 5 years ago
Answer
LOL. I already solved the problem. Result:
var matchID = Spark.getData().mid;
var participantsData = Spark.getData().pdata;
var matchDetails = Spark.getMultiplayer().loadMatch(matchID);
var newMatchData = matchDetails.getMatchData();
for(var i = 0; i < participantsData.length; i++)
{
newMatchData.participants[i].heals = participantsData[i].heals;
newMatchData.participants[i].damage = participantsData[i].damage;
newMatchData.participants[i].blockPoint = participantsData[i].blockPoint;
newMatchData.participants[i].attackPoint = participantsData[i].attackPoint;
}
matchDetails.setMatchData({"participants": newMatchData.participants});
Vitaly Evtukh
Good day.
I have a problem with json variable.
In atributes (Events) I make variable type - json. If I want to receive data from json file - the data is null.
Here is the code:
Thanks in advance
LOL. I already solved the problem.
Result:
Vitaly Evtukh
LOL. I already solved the problem.
Result:
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics