Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Random math in API?

I am trying to create an API script that will give a random result (which I have gotten to work) and within the posted result have the script also randomly generate a number. For instance: {low:  7, high:  8, result: "Extra Damage", effect: "You have taken a serious hit, As a result you suffer an additional XXXX hp of damage. "}, With XXXX being the randomly generated number.  I know roll 20 has the  Math.random() function but i cannot seem to figure out where to insert it.
1587824601
GiGs
Pro
Sheet Author
API Scripter
In roll20 there is also the randomInteger() function. For inserting, you can do this {low:  7, high:  8, result: "Extra Damage", effect: `You have taken a serious hit, As a result you suffer an additional ${randomInteger(6)+6} hp of damage. `}, randomInteger(6)+6 is the equivalent of 1d6+6. Notice the style of quotes are backticks, not single or double quotes, found at the top left of most keyboards. If you have a string with backticks, you can put ${ } in it, and then inside the curly brackets you can put any valid javascript code.