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

Break input into objects (Javascript)

1622513591

Edited 1622513610
I'm here planning some changes on my custom sheet and a doubt came up. Is it possible to break an input into smaller variables with javascript? for example: let dice = 1d10+3 and break it down into "1", "d10", "+3" or "1","d","10","+","3" I found some stuff about regex I could possibly use, not sure if roll20 supports it thou. I'm here still taking babysteps with Java 
1622517380
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Regex is what I'd recommend for this. And yes, it is supported.
1622526571
GiGs
Pro
Sheet Author
API Scripter
As Scott says, you can do this, but you have to bear in mind that if you are allowing humans to enter text, sometimes (often) you will end up with error. It is generally better to make sure players can only enter valid input, but creating, for example, separate input boxes for number of dice, die size, and modifier, and then in your sheet worker, construct them into the code you actually want to use.