RPG gaming dice roll skill checker script question

…衆ロ難τιáo~ 提交于 2020-03-05 00:22:24

问题


For my RPG gaming skill check script... In the below script (created by Edmund chan kei yun, a member at StackOverflow) cells are checked for the highest numbers (after simulated several d6 dice rolls by another script), and then text is copied from a table (to define resulting actions).

I would also need dice result combos like 666 and 111 to have their own table results. Such will have their own columns/rows in the table. Could someone help me to update the script to include the reading of combos of dice result as well, so that such combo directs to a specific column/row?

Here is a link to an editable version of the sheet with script... https://docs.google.com/spreadsheets/d/1zYhUnlHCW7kfo0rf1pZY2GNI4qt5PsbGYOljFe2dwJE/edit?usp=sharing

function SetRetrievedValue() {
  var app = SpreadsheetApp;
  var ss = app.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  //var cellcontent1 = sheet.getRange(2,1,6,1).getValues(); use this if its a range of cells you are searching
  var cell1 = sheet.getRange(1,1).getDisplayValue(); //gets value as string
  var cellcontent1 = cell1.split(""); // splits up the string individually
  var newcellcontent1 = Array.prototype.concat.apply([], cellcontent1); // flatten the array
  var maxNum1 = Math.max.apply(null, newcellcontent1); //gets the max value in the array

  // repeat of cell 1
  var cell2 = sheet.getRange(1,2).getDisplayValue(); 
  var cellcontent2 = cell2.split("");
  var newcellcontent2 = Array.prototype.concat.apply([], cellcontent2);
  var maxNum2 = Math.max.apply(null, newcellcontent2);


  var tablecell = ss.getSheetByName("Table sheet").getRange(maxNum1,maxNum2).getValue(); //retrieve the value based on the corresponding max value
  sheet.getRange(1,3).setValue(tablecell); // sets the cell C1 as the value retrieved from the table
}

回答1:


it might be better if you adjust the script by yourself, but what i can help you with is the checking for specific combos. what you would want is to check for combo cases prior to checking for highest value, since combos take precedence.

Since the only combos are 666 and 111, we can use an if statement to change the row/column that is checked to 7. Therefore this is the only addition you would need to your script.

  if (newcellcontent1[0]=== '6' && newcellcontent1[0]===newcellcontent1[1] && newcellcontent1[1]===newcellcontent1[2]) { //if attacker rolls a 666
    maxNum1 = 7;
  }
  if (newcellcontent2[0]=== '1' && newcellcontent2[0]===newcellcontent2[1] && newcellcontent2[1]===newcellcontent2[2]) { //if defender rolls a 111
    maxNum2 = 7;
  }

  var tablecell = ss.getSheetByName("Table sheet").getRange(maxNum1,maxNum2).getValue(); //retrieve the value based on the corresponding max value
  sheet.getRange(1,3).setValue(tablecell); // sets the cell C1 as the value retrieved from the table

Please try to make any minor changes to the script by yourself and accept this answer if it helped you.

This is the google sheet that i used https://docs.google.com/spreadsheets/d/1NSpdsqQ2-c20EANnYoiKWQHNTu05C-7NGr0Y7K9on8A/edit?usp=sharing



来源:https://stackoverflow.com/questions/60261990/rpg-gaming-dice-roll-skill-checker-script-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!