Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nightStart(nightNumber, playersArray, roleList) {
- var sheet = SpreadsheetApp.getActiveSpreadsheet();
- var range = sheet.getRange("Controls!G3:G1000");
- var wakeupOrder = [];
- var sleeping;
- var role;
- //collecting the array to define in what order roles wake up
- for (var i = 1; i<=20; i++) {
- var cellValue = range.getCell(i,1).getValue();
- wakeupOrder.push(cellValue);
- }
- //the FOR loop that I am trying to make work (open Dialog for each role)
- for (index in wakeupOrder) {
- role = wakeupOrder[index];
- if (roleList.indexOf(role) != -1) {
- sleeping = true;
- roleWakeUp(role, playersArray, roleList);
- do {
- Utilities.sleep(2000);
- //calling global sleeping parameter that is defined as FALSE in the 'nightTargetSelection' function
- sleeping = PropertiesService.getScriptProperties().getProperty('sleeping');
- } while (sleeping != false);
- }
- }
- }
- //below is the function that opens the modal dialog (but the server side code still keeps running).
- function roleWakeUp (role, playersArray, roleList){
- //I have removed all code from here for Stack Overflow. The only part that I believe is important is that it opens an HTML dialog with a form
- SpreadsheetApp.getUi().showModalDialog(actionInputDlg, wakeUpText);
- }
- //Below function is called by the client on HTML form submission. After this form is submitted I need the next dialog to open (i.e need the Utilities.sleep to stop running
- function nightTargetSelection (selected, playerNumber){
- var sleeping = false;
- PropertiesService.getScriptProperties().setProperty('sleeping', sleeping);
- }
- // Open a dialog
- function openDialog(jobs, i) {
- var template = HtmlService.createTemplateFromFile('index');
- template.jobs = JSON.stringify(jobs);
- template.index = i;
- SpreadsheetApp.getUi().showModalDialog(template.evaluate(), "sample");
- }
- // When all jobs were finished, this function is called.
- function done(e) {
- Logger.log(e)
- }
- // Please run this script
- function start() {
- var jobs = ["sample1", "sample2", "sample3"];
- openDialog(jobs, 0);
- }
- <div id="currentjob"></div>
- <input type="button" value="ok" onclick="sample()">
- <script>
- var jobs = JSON.parse(<?= jobs ?>);
- var index = Number(<?= index ?>);
- document.getElementById("currentjob").innerHTML= "currentJob: " + jobs[index] + ", index: " + index;
- function sample() {
- if (index < jobs.length - 1) {
- google.script.run.openDialog_1(jobs, index + 1);
- } else {
- google.script.run.withSuccessHandler(()=>google.script.host.close()).done("Done.");
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement