Im not a javascript dev but i have to use it for my backend. For some reason coming from an objective c background i cannot perform the most simple tasks in javascript. All i want to do is save this string that is in the variable "thePlayer" to my backend under the key "playerName." Ignore everything else. its all about lines 2, 13, and 24. My cloud log keeps saying the key "playerName" was expecting a string but got an object. So my question is why is thePlayer getting saved as an object?
Parse.Cloud.define("getUsers", function(request, response) {
var thePlayer = new String(); <<<***********************************************
var query = new Parse.Query(Parse.User);
query.find({
success: function(results){
var users = [];
//extract out user names from results
for(var i = 0; i < results.length; ++i){
users.push(results[i].id);
}
var rand = users[Math.floor(Math.random() * users.length)];
console.log("The random user is" + rand);
thePlayer = rand; <<<******************************************************
response.success(users);
}, error: function(error){
response.error("Error");
}
});
var GameScore = Parse.Object.extend("Messages");
var gameScore = new GameScore();
gameScore.set("score", 1337);
gameScore.set("playerName", thePlayer); <<<**************************************************
gameScore.set("cheatMode", false);
gameScore.save(null, {
success: function(gameScore) {
// Execute any logic that should take place after the object is saved.
alert('New object created with objectId: ' + gameScore.id);
},
error: function(gameScore, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
}
});
});
=for assignment, two==for comparison.