Here’s a fun Snippet to try, especially if you like board games, and it’s a great way to get your feet wet with scripting. Create a Snippet with JavaScript as the Content Type, and put this code into the content field:
// Function to generate a random number between 1 and 20
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Generate the random number and output it
getRandomNumber(1, 20);
This simulates rolling a 20-sided die by generation a random number from 1-20. I set my abbreviation for this Snippet to ;d20.
You can change the 20 to another number to emulate another die. For instance, change 20 to 6 and it behaves like a traditional six-sided die.
You could totally create different Snippets for different kinds of rolls. For instance, if you have a +2 bonus to initiative, you could bake in that math in a separate Snippet:
// Function to generate a random number between 1 and 20, with a +2 modifier
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min + 2;
}
// Generate the random number and output it
getRandomNumber(1, 20);
This is your space to ask questions, find support, and share ideas with fellow TextExpander users and our product team. As a first step, take a moment to introduce yourself to the community.