i'm trying grasp parse.com's cloud code difficult. issue want rewrite query manipulates array in cloud code (javascript)
here of code
pfquery * quer = [pfquery querywithclassname:@"spel"]; nsstring * playerid = [[pfuser currentuser] objectforkey:@"fbid"]; [quer wherekey:@"lobby" containsallobjectsinarray:@[playerid]]; [quer findobjectsinbackgroundwithblock:^(nsarray * _nullable objects, nserror * _nullable error) { (pfobject * obj in objects) { if (!error) { nsmutablearray * ready = [[obj objectforkey:@"ready"] mutablecopy]; if (![ready containsobject:[[pfuser currentuser] objectforkey:@"fbid"]]) { [ready addobject:[[pfuser currentuser] objectforkey:@"fbid"]]; } [obj setobject:ready forkey:@"ready"]; [obj saveinbackgroundwithblock:^(bool succeeded, nserror * _nullable error) { if (succeeded) { //success}
i have same code run in cloud code, since it's multiplayer game , people click button @ same time, there issue array manipulated faulty.
some kind soul out there know how this? since feels little more complex saving normal object cloud code
kind regards, martin
it looks code finds spel objects current user's "fbid" in spel's "lobby" array. each 1 found, add user's "fbid" spel's "ready" property.
you'd in js follows:
var _ = require('underscore'); parse.cloud.define("mycloudfunction", function(request, response) { var fbid = request.user.get("fbid"); var query = new parse.query("spel"); query.equalto("lobby", fbid); query.find().then(function(results) { _.each(results, function(spel) { spel.addunique("ready", fbid); }); return parse.object.saveall(results); }).then(function(result) { response.success(result); }, function(error) { response.error(error); }); });
Comments
Post a Comment