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

Is there a way to sendChat an array of numbers using the default roll template style?

1633110338

Edited 1633114285
Hello, I am creating a custom API for the specific way of calculating rolls of Anima Beyond Fantasy and I would like to publish the result of the roll using the default roll template style. The following example will clarify my question: Given an array of numbers that I calculate previously, lets say [95, 93, 26], I would like to publish them in the chat following the same style as if they had been rolled with [[3d100cs>90]], that is: only the sum would appear, as there was a critical success a green rectangle would be visible around the sum and if you hoover the mouse over the number you would see a pop up window showing the roll Rolling something = (95 (green) + 93 (green) + 26). I am bad with HTML so it would be ideal for me if I could avoid writing the display myself.
1633114443

Edited 1633114517
The Aaron
Roll20 Production Team
API Scripter
The roll template part is easy, getting the roll data to show up is more complicated. The pop ups are from a library called tipsy. They use CSS classes to set up the various hover boys, and use the contents of the title attribute as the tool tip text. ImperialCalendar makes heavy use of them.  Tim has a library that builds the output for inline rolls like you're looking for. Check out libInline for that. 
Thanks for your reply. I had copied the html part of the showhelp function of your ImperialCalendar and was extracting the lines that make little things into rectangles but libInline has exactly what I want in the getRollTip function so I will try to make it work.  As I am writing this message there are a lot of things I do not understand at all from libInline but the lines that create the html string and call the tipsy library are full of constants and easy to understand so I could make it work with my own code. I will leave here the important information in case someone needs it in the future. The lines are 266-269: parts . push ( `<span class="inlinerollresult showtip tipsy-n-right" ${ baseInlineCSS } ` ) ; parts . push ( ` ${ bordercolors [ ( / basicdiceroll (?: \s critsuccess ) ? \s critfail / . test ( roll . display ) ? 1 : 0 ) + ( / basicdiceroll \s critsuccess / . test ( roll . display ) ? 2 : 0 ) ] } " ` ) ; parts . push ( `title=" ${ HE ( HE ( `Rolling ${ roll . expression } = ${ roll . display } ` ) ) } "> ${ roll . value } </span>` ) ; return parts . join ( '' ) ;
1633127614
The Aaron
Roll20 Production Team
API Scripter
libInline is designed to be a script you install and use from your own script, there should be some examples of that in the thread. 
1633143842
timmaugh
Forum Champion
API Scripter
Yep, here's an example of what Aaron is talking about. libInline exposes functions that any script can make use of, so if you can be sure that it is installed for a particular game, you know you are safe to call those functions. Here's how you would test for it existing:     on('ready', () => {         if('undefined' === typeof libInline) {              // notify of the missing library             sendChat('',`/w gm <div style="color:red;font-weight:bold;border:2px solid red;background-color:black;border-radius:1em;padding:1em;">Missing dependency: libInline</div>`);         }     }); Then in your script, you can call the exposed functions from libInline: libInline.getRollData(msg.inlinerolls); There are functions exposed from the libInline object like this, which take various input (the message object, the inlinerolls object, an array of rolls, an individual roll) and return a particular piece of information. However, the return of the getRollData() function is a an array of parsed roll information with functions attached to each roll. So typically you would call getRollData() on all of the inlinerolls in your message object, then use the returned object to get the roll value, equation, dice (by some filter), or roll tip. // assign the return of the getRollData function to an object let parsedInlineRolls = libInline.getRollData(msg); // replace all of the roll markers -- like $[[0]] -- in the command line of the message with the roll tip msg.content = msg.content.replace(/\$\[\[(\d+)]]/g, ((m, g1) => parsedInlineRolls[g1].getRollTip())); There are quite a few things you can do with the library, but that should get you started on what you originally mentioned you wanted to do with the roll tip.
1633156291

Edited 1633156304
Hello, thanks for your kind replies. I have installed libInline and now I understand how to use it in my API with the roll messages from the chat.  Moreover, I know exactly what I want to do with libInline but I do not know how to do it so let me ask it. What I exactly need is to create my own libInline roll object without parsing it from a chat roll message and then assign my specific values to the libInline roll object. I think it would look something like this: let myRoll= libInline.getRollData(); This would create an empty roll object without the need of a message. myRoll[0].setParameter("expression", "myExpression"); myRoll[0].setParameter("parsed", "myParsed"); myRoll[0].setParameter("total", myTotal); ... This would assign my own values to the object. Given that, I would be able to use the libInline functions: var rollString = getRollTip(myRoll); Is there a way to do this that I am not aware of?
1633182856
The Aaron
Roll20 Production Team
API Scripter
It would probably be easier to generate your own message object with the .inlinerolls property set with your values, then pass that to libInline to format. 
1633189651

Edited 1633198338
Ok I will try that. Inside the inlineroll property, .rollid and .signature properties are important? or can I made them up in my made up message? Edit1: I have been playing around with this idea but it is not working for me, is there something wrong in this code? var msgFake = {"content":"$[[0]]","inlinerolls":[{"expression":"1d100!>50cs>50cf<3","results":{"resultType":"sum","rolls":[{"dice":1,"mods":{"customCrit":[{"comp":">=","point":50}],"customFumble":[{"comp":"<=","point":3}],"exploding":{"comp":">=","point":50}},"results":[{"v":88},{"v":63},{"v":4}],"sides":100,"type":"R"}],"total":155,"type":"V"},"rollid":"-Ml0w_1iYbZL5AeuDKiY","signature":"a6251b9ddfdd4c37dbe481b551bf974b987f5704622198855f98fac18aca644ed2866d34d01aa70047081403695368f8cacd7f96ccc8da9b32b0a978a138be70"}],"playerid":"-MkoxyD_xpHd2YI6xUYq","type":"general","who":"Master (GM)"}; var pir = libInline.getRollData(msgFake); var rollStr = pir[0].getRollTip(); sendChat("API: ", `${rollStr}`); I copied msgFake from the log(msg) of a message I wrote manually in chat to have something to start with but I am not sure if that is the same as a chat:message  variable. rollStr is like this: "<span class=\"inlinerollresult showtip tipsy-n-right\" style=\"-webkit-tap-highlight-color: rgba(0,0,0,0);font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;color: #404040;line-height: 1.25em;box-sizing: content-box; background-color: #FEF68E; padding: 0 3px 0 3px; font-weight: bold; cursor: help; font-size: 1.1em;border: 2px solid #3FB315;\" title=\"Rolling 1d100!>50cs>50cf<3 = (<span class="basicdiceroll critsuccess ">88</span>+<span class="basicdiceroll critsuccess ">63</span>+<span class="basicdiceroll">4</span>)\">155</span>" Here all the format looks right and you can see the information of the hover-mouse window in tittle: title=\"Rolling 1d100!>50cs>50cf<3 = (<span class="basicdiceroll critsuccess ">88</span>+<span class="basicdiceroll critsuccess ">63</span>+<span class="basicdiceroll">4</span>) Which is the roll I wrote in the chat 1d100!>50cs>50cf<3 and libInline adds the = 88+63+4 with 88 and 63 critsuccess. So everything looks nice but when I publish it in the chat this is what I see: The tittle hover-mouse window seems corrupted and does not show correctly. Edit2: It is the "cf<3 = (", if I remove it everything works fine. I do not know how to solve it so I will just avoid it.
1633271871
timmaugh
Forum Champion
API Scripter
Hmm... If I run your roll equation through libInline (using ZeroFrame as the message out-putter), I seem to get an extra paren at the back end: ![[ 1d100!>50cs>50cf<3 ]] {&simple} That might be related. Let me see if I can get to the bottom of what might happening.
I think that is not an extra parenthesis, it is from what you would actually see if the output was correct. In the roll you are showing I think the output should be something like 1d100!>50cs>50cf <A = (dice1 + dice2 + ... + 33) so there is no extra ) at the end