Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. function nightStart(nightNumber, playersArray, roleList) {
  2. var sheet = SpreadsheetApp.getActiveSpreadsheet();
  3. var range = sheet.getRange("Controls!G3:G1000");
  4. var wakeupOrder = [];
  5. var sleeping;
  6. var role;
  7.  
  8. //collecting the array to define in what order roles wake up
  9. for (var i = 1; i<=20; i++) {
  10. var cellValue = range.getCell(i,1).getValue();
  11. wakeupOrder.push(cellValue);
  12. }
  13.  
  14. //the FOR loop that I am trying to make work (open Dialog for each role)
  15. for (index in wakeupOrder) {
  16. role = wakeupOrder[index];
  17. if (roleList.indexOf(role) != -1) {
  18. sleeping = true;
  19. roleWakeUp(role, playersArray, roleList);
  20. do {
  21. Utilities.sleep(2000);
  22. //calling global sleeping parameter that is defined as FALSE in the 'nightTargetSelection' function
  23. sleeping = PropertiesService.getScriptProperties().getProperty('sleeping');
  24. } while (sleeping != false);
  25. }
  26. }
  27. }
  28.  
  29.  
  30.  
  31. //below is the function that opens the modal dialog (but the server side code still keeps running).
  32. function roleWakeUp (role, playersArray, roleList){
  33. //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
  34. SpreadsheetApp.getUi().showModalDialog(actionInputDlg, wakeUpText);
  35. }
  36.  
  37.  
  38.  
  39. //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
  40. function nightTargetSelection (selected, playerNumber){
  41. var sleeping = false;
  42. PropertiesService.getScriptProperties().setProperty('sleeping', sleeping);
  43. }
  44.  
  45. // Open a dialog
  46. function openDialog(jobs, i) {
  47. var template = HtmlService.createTemplateFromFile('index');
  48. template.jobs = JSON.stringify(jobs);
  49. template.index = i;
  50. SpreadsheetApp.getUi().showModalDialog(template.evaluate(), "sample");
  51. }
  52.  
  53. // When all jobs were finished, this function is called.
  54. function done(e) {
  55. Logger.log(e)
  56. }
  57.  
  58. // Please run this script
  59. function start() {
  60. var jobs = ["sample1", "sample2", "sample3"];
  61. openDialog(jobs, 0);
  62. }
  63.  
  64. <div id="currentjob"></div>
  65. <input type="button" value="ok" onclick="sample()">
  66. <script>
  67. var jobs = JSON.parse(<?= jobs ?>);
  68. var index = Number(<?= index ?>);
  69. document.getElementById("currentjob").innerHTML= "currentJob: " + jobs[index] + ", index: " + index;
  70.  
  71. function sample() {
  72. if (index < jobs.length - 1) {
  73. google.script.run.openDialog_1(jobs, index + 1);
  74. } else {
  75. google.script.run.withSuccessHandler(()=>google.script.host.close()).done("Done.");
  76. }
  77. }
  78. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement