I'm using Google Sheets for remote gaming with an elderly friend (with the game publisher's permission).
I am trying to use an HTML dialog with buttons to trigger some script. I've worked through all the examples I can find in the documentation and on Yagisanatode's blog. Every part of the thing works except that google.script.run.addEgg()
isn't triggering the addEgg()
function in Code.gs.
I'm including the relevant bits of code. I'm working on getting one button to trigger one script before building things out further.
EggFoodTuck01()
, triggered by clicking an ObjectOverGrid
, successfully launches the dialog
function EggFoodTuck01(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('Decks'));
sheet.getRange('CurrentCard').setValue(0); // Record Card Number in 'CurrentCard' Cell (0-14)
sheet.getRange('CurrentSheet').setValue('Player 1'); // Record Sheet Name in 'CurrentSheet'
// Launch dialog
var html = HtmlService.createHtmlOutputFromFile("EFTDialog");
ui.showModalDialog(html, "What would you like to do?");
}
The HTML dialog displays correctly. Clicking the [+ Egg] button launches actionAddEgg()
, because the dialog closes. For whatever reason, addEgg()
isn't running in my Apps Script.
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<div>
<br>
<br>
<input type="button" value="+ " class="share" onclick="addEgg()" />
<br>
<br>
<input type="button" value="Cancel" class="action" onclick="google.script.host.close()" />
</div>
<script>
function addEgg(){
google.script.run.addEgg();
google.script.host.close();
}
</script>
</body>
</html>
Here's addEgg()
in the Apps Script. It's not running at all. The 'card' variable won't even log.
function addEgg(){
// Get card and sheet data
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('Decks'));
var card = sheet.getRange('CurrentCard').getValue();
var sheetname = sheet.getRange('CurrentSheet').getValue();
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName(sheetname));
// Get current egg value and +1
var eggCell = ['F7','M7','T7','AA7','AH7','F16','M16','T16','AA16','AH16','F25','M25','T25','AA25','AH25'];
var egg = sheet.getRange(eggCell[card]).getValue();
sheet.getRange(eggCell[card]).setValue(egg + 1);
}