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

HTML formulae in API

I'm having trouble getting JavaScript to calculate the ability score formulas. Currently, (ceil((15-15)/1e100)*ceil((15-15)/2)*((ceil((15-30)/1e100)-1)*(-1)))+(ceil((15-30)/1e100)*(8))+2 resolves to 0, even when I try and "roll" it using the send chat function. At the very minimum, it should resolve to 2. Any ideas?
1413684692

Edited 1413684712
Lithl
Pro
Sheet Author
API Scripter
Charles H. said: (ceil((15-15)/1e100)*ceil((15-15)/2)*((ceil((15-30)/1e100)-1)*(-1)))+(ceil((15-30)/1e100)*(8))+2 1e100 is a very large number. Are you sure that's correct for your formula? (As opposed to 1d100, which is a 100-sided die.) I suspect the dice engine is being tripped up by the scientific notation.
It's 1e100 because I need to reduce the number to between 0 and 1, so ceil returns 1 if over a certain value and 0 if under a certain value. This is necessary because in Heroes Unlimited, ability scores provide a bonus if over 15, but don't provide a penalty if under that value. This means a standard slope/intercept formula can't be used to calculate the bonus, like in D&D.
1413701758
Lithl
Pro
Sheet Author
API Scripter
What are you doing exactly, that is producing 0?
Use {0, math}kh1 for figuring out the bonus. Anything less than zero will default to zero.
The formula I gave is in the custom character sheet and is used for determining ability score bonuses. When I grab that value in a macro and pass it to my script, it doesn't grab 2, like it should in this case, it grabs the formula. I tried "rolling" it, using SendChat and grabbing the value that comes out, but that only returned 0. Most things I try that attempts to evaluate that string either returns 0, NaN, or crashes the API.
1413732403
The Aaron
Roll20 Production Team
API Scripter
This works for me: sendChat('','[[(ceil((15-15)/1e100)*ceil((15-15)/2)*((ceil((15-30)/1e100)-1)*(-1)))+(ceil((15-30)/1e100)*(8))+2]]',function(r){ AaronsDebugFunction(r); }); and produces this: [ . { . . "who": "", . . "type": "general", . . "content": "$$[[1]]", . . "playerid": "API", . . "avatar": false, . . "inlinerolls": { . . . "1": { . . . . "expression": "(ceil((15-15)/1e100)*ceil((15-15)/2)*((ceil((15-30)/1e100)-1)*(-1)))+(ceil((15-30)/1e100)*(8))+2", . . . . "results": { . . . . . "type": "V", . . . . . "rolls": [ . . . . . . { . . . . . . . "type": "M", . . . . . . . "expr": "(ceil((15-15)/1e+100)*ceil((15-15)/2)*((ceil((15-30)/1e+100)-1)*(-1)))+(ceil((15-30)/1e+100)*(8))+2" . . . . . . } . . . . . ], . . . . . "resultType": "M", . . . . . "total": 2 . . . . } . . . } . . } . } ] Which has the correct value of 2 .
Figured out the problem. It wasn't with the HTML formula, it was with my input validation. I had if(techbonus = "FAIL") instead of if(techbonus == "FAIL"). %&$*&