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

Correct formatting of inline rolls.

1467889535

Edited 1467900460
Jakob
Sheet Author
API Scripter
I'm writing a script that outputs an inline roll via sendChat. I'll condense it to the important part. The following works fine: output += "<p><b>" + character.get("name") + ":</b> \[\[" + die + " + \@\{" + character.get("name") + "\|strength"  + "\}\]\]</p>";  ... sendChat(msg.who, output);  The following does not work. output += "<p><b>" + character.get("name") + ":</b> \[\[" + die + " + \@\{" + character.get("name") + "\|strength_saving_throw_mod"  + "\}\]\]</p>";  ... sendChat(msg.who, output);  The only difference: strength has a value of e.g. 16, whereas strength_saving_throw_mod is e.g. 3[str] + 3[proficient] + 0[global saving throw bonus] The error message I get is Could not determine result type of: [{"type":"M","expr":"10+3"},{"type":"L","text":"str"},{"type":"M","expr":"+3"},{"type":"L","text":"proficient"},{"type":"M","expr":"+0"},{"type":"L","text":"global saving throw bonus"}] undefined Oh mighty wisdom of the API subforum, how do I make this work? Extra caveat: in the end, I actually want to make the following work: output += "<p><b>" + character.get("name") + ":</b> \[\[" + die + " + \@\{" + character.get("name") + "\|" + attrMod  + "\}\]\]</p>";  where attrMod is e.g. 'strength_saving_throw_mod'.
You don't need to escape the square brackets. "[[" + die + "]]" will work.
1467891173
Jakob
Sheet Author
API Scripter
SkyCaptainXIII said: You don't need to escape the square brackets. "[[" + die + "]]" will work. Hmm, cool. I escaped everything I could in a frenzy, trying to get rid of the error.
1467897669
The Aaron
Pro
API Scripter
Now that the API is on Javascript ES6, you can use the new  Template Literals to do this more concisely: output += `<p><b> ${character.get("name")} :</b> [[ ${die} + @{ ${character.get("name")} | ${attrMod} }]]</p>`;  Template Literals are a string denoted by backticks ( ` ) instead of single ( ' ) or double ( " ) quotes.  Within them, anything inside ${ } will be expanded to it's value, including the result of function invocations.
1467899298
Jakob
Sheet Author
API Scripter
That's certainly nicer to write, but it still produces the same error (which happens in the line where sendChat is called).
1467899605

Edited 1467899840
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
if you change the Stength saving throw value to not have the roll tags, does it work? From that error message, it looks like it's trying to add 10+3+Str+3+Proficiency+0+global saving throw bonus and throwing an error because obviously "str", "proficiency", and "global saving throw bonus" are not numbers and so can't be added. Looks to me like the API doesn't work with roll tags (at least in this situation).
1467900059
Jakob
Sheet Author
API Scripter
Scott C. said: if you change the Stength saving throw value to not have the roll tags, does it work? From that error message, it looks like it's trying to add 10+3+Str+3+Proficiency+0+global saving throw bonus and throwing an error because obviously "str", "proficiency", and "global saving throw bonus" are not numbers and so can't be added. Looks to me like the API doesn't work with roll tags (at least in this situation). Yes, it works without the roll tags.What I really wanted to ask, I suppose: is there a way around reading the attribute myself and stripping away all the roll tags before passing it to sendChat(which I really don't want to do, since I don't know any JS)?
Try adding 0d0 + at the beginning.
1467902627
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
What happens if you add an additional set of inline roll brackets?
1467903088
Jakob
Sheet Author
API Scripter
SkyCaptainXIII said: Try adding 0d0 + at the beginning. That actually did it, thanks!