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

Dice Syntax Verification and the Inline API...

One of my scripts is using the Inline Processor to get complex die rolls from Roll20's chat command and everything about that works just fine, with one small exception... In the script, there is a variable "diceformula" that holds the requested formula, either from a chat argument or from an attribute (like HD_Formula.current = "5d6+5d8+30"). That formula is sent to the Inline Processor and I get a result just fine... UNLESS the formula is not in a format that Inline Processor can accept. Since the formula is from user input and not pre-assembled, when an invalid formula is sent up, it gets the familiar Syntax Error and the rest of the script fails out. So, the question is... Is there a way to evaluate a string to see _IF_ it is a valid formula before sending it to get the actual die result? Ideally something that returns true/false so I can add something like " if(IsFormula(formula)) { InlineProcessor(formula); } "
1476069905
The Aaron
Pro
API Scripter
There is nothing built in for that. You could likely write something to evaluate the validity of a formula, but that would probably be complex enough you might as well write hoot on roller.  As an alternative, you could catch the exception and issue a warming instead, something like: try { InlineProcessor(formula); } catch(e) { showError(e.message); }
Thanks much. The try/catch did the trick.
1476142653
The Aaron
Pro
API Scripter
Great!