Helps your Spreadsheets interact with Parse.com.
The Google Apps Script gallery is being finnicky, so for now, this is the easiest way to get started:
- Copy
parse.gs
. - Create a new Google Spreadsheet.
- Create a new sheet and make sure it is first sheet (closes to left side of the screen).
- Enter your Parse Application ID in Cell B:1 and your Parse REST API Key in Cell B:2.
- Tools -> Script Editor
- Paste
- See
examples.gs
or below:
parseInsert("GameScore",{
"score" : 1000,
"playerName" : "Sean Plott"
});
results = parseQuery("GameScore", {
'playerName' : 'Sean Plott'
});
var objectId = results[0].objectId;
parseUpdate("GameScore", objectId, {
"playerName" : "Sean Plott III"
});
parseFindOrCreateByAttribute("GameScore",{
"playerName" : "Sean Plott"
});
Here's a neat trick to run cron tasks for free:
- Open the Google Apps Script editor.
- Define function that you want to run in the cron task.
- Resources -> Current Script Triggers
- Select the function from step two, and customize to your needs.
Let's say you're running a script that will tally the score for a multiplayer game. You have a class called Game
with the boolean field scored
, the integer fields homeScore
and awayScore
, and a string field winner
.
Let's load some sample data:
function setupData() {
parseInsert("Game", {
"scored" : true,
"homeScore" : 55,
"awayScore" : 44,
"winner" : "home"
});
parseInsert("Game", {
"scored" : false,
"homeScore" : 99,
"awayScore" : 59
});
parseInsert("Game", {
"scored" : false,
"homeScore" : 46,
"awayScore" : 12,
});
parseInsert("Game", {
"scored" : false,
"homeScore" : 66,
"awayScore" : 100,
});
}
And here's the scoring script:
function scoreGames() {
var games = parseQuery("Game", {
"scored" : false
});
for (var i = 0; i < games.length; i++) {
var objectId = games[i].objectId;
var winner;
if (games[i].homeScore > games[i].awayScore) { // home team wins
winner = "home";
} else if (games[i].homeScore < games[i].awayScore) { //away team wins
winner = "away";
} else { // tie
winner = "tie";
}
parseUpdate("Game", objectId, {
"scored" : true,
"winner" : winner
});
}
}
So to get this script to run every minute, just click "Resources" -> "Current Script Triggers", then select "scoreGames()" from the function list and set it to run every minute.