MissEshock2002

SexScripts Dice Roll Example

Aug 2nd, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.61 KB | None | 0 0
  1. // Dice Roll Example
  2. // by MissEshock2002
  3.  
  4. // This script, from https://ss.deviatenow.com, is protected by this licence:
  5. // CC0
  6.  
  7. setInfos(9, "Dice Roll Example", "Dice Roll Example for 1 or more Dice",
  8.         "MissEshock2002",
  9.         "v1.0", 0x222222, "en", ["example", "tutorial"]);
  10.  
  11.  
  12. def getDiceRoll = { numberOfDice = 1 -> // default 1 dice, if no value given
  13.     // returns the sum of numberOfDice rolled dice
  14.  
  15.     int rollSum = 0 // sum of all rolled dice
  16.  
  17.     // loop: repeats numberOfDice times
  18.     (1..numberOfDice).each {
  19.         // getRandom(6): random between 0 and 5; +1 to get 1 to 6
  20.         // roll += ... sums up all rolls
  21.         rollSum += getRandom(6) + 1
  22.     }
  23.  
  24.     return rollSum
  25. }
  26.  
  27.  
  28. int numberOfDice = 1
  29.  
  30. boolean endLoop = false
  31. while (!endLoop) { // loop repeats till endLoop = true
  32.  
  33.     // while loop to make sure input is positive number
  34.     // repeat, if input is wrong
  35.     while (true) {
  36.         numberOfDice = getInteger("How many dice to roll?", numberOfDice)
  37.         if (numberOfDice > 0) break // if input is correct: end while loop with break
  38.     }
  39.  
  40.     int roll = getDiceRoll(numberOfDice)
  41.  
  42.     // same as if ... else ...: (condition) ? "condition is true" : "condition is false"
  43.     String diceWord = (numberOfDice == 1) ? "Die" : "Dice"
  44.  
  45.     // show results:
  46.     show("You rolled " + roll + " with " + numberOfDice + " " + diceWord + ".")
  47.     // show(String.format("You rolled %s with %s %s.", roll, numberOfDice, diceWord)) // the same with formatted string
  48.  
  49.     showButton("->")
  50.  
  51.     if (!getBoolean("Repeat?")) endLoop = true
  52. }
  53.  
  54. show("- End of Script -")
Add Comment
Please, Sign In to add comment