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

[Script Help] I'm losing the roll formatting when I call a character ability through an API command, is there a solution?

1677169929

Edited 1677170037
Adam F.
Pro
Marketplace Creator
Hello, I'm working on an API script to help with Conjure Animals; the script shows several buttons in the chat that I click to spawn tokens, roll attacks and roll damage. The buttons call abilities from my character sheet. The issues I have is that when I click the 'Roll Ability' button on the character sheet, then the rolls are nicely formatted so I can hover the cursor to see roll details, but when I call the Ability macro using the "sendChat(msg.who, message);" API command the formatting is gone and I only see plain numbers. Is there a solution to be able to call the macro and keep the formatting? This is what I am seeing:&nbsp;<a href="https://www.screencast.com/t/bsWTLnpyL09" rel="nofollow">https://www.screencast.com/t/bsWTLnpyL09</a>
1677170863
timmaugh
Pro
API Scripter
You have to build the roll tips, yourself, for messages you send from the API... which can be a pain. Easiest way to solve it is to use libInline as a dependency in your script and let it construct the roll tip for you. There's more info in the thread, but the idea would be: 1. Establish libInline as a dependency 2. submit your inline rolls to libInline to get a "parsed inline" object back (containing relevant data points like dice, included dice, dropped dice, success, failures, and roll tip). 3. Construct your outgoing message using the appropriate roll tip wherever you would want to display the particular roll's result.
1677183461
Adam F.
Pro
Marketplace Creator
I'm struggling to get this implemented. I keep getting an undefined error whenever I try to use the data. var message = "(8*1)d4+4*8" let par = libInline.getRollData(message); log(par.expression); Returns:&nbsp; TypeError: Cannot read property 'expression' of undefined TypeError: Cannot read property 'expression' of undefined
1677188590
timmaugh
Pro
API Scripter
That's not quite the way you would use it. libInline is going to process inline rolls as returned from the Roll20... try this... Your script has some function that answers the on('chat:message') event. It might look like this: on('chat:message', msg =&gt; { &nbsp; // do stuff }); Or it might look like: const handleInput = msg =&gt; { &nbsp; // do stuff }; And in that function you'll have a way to catch only the messages that are intended for your script... typically looking for your script handle. I'll pretend that's "conjure". if(msg.type !== 'api' || !/^!conjure/.test(msg.content)) return; So if the message isn't a bangsy message (intended for the Scirpt Moderator) or if the message doesn't match your handle, just get out of the function and do nothing. Next, assume that your command line is just your handle, a space, and then an inline roll. In practice this would be more complex (and would require a lot more sanitizing), but for the sake of example and since we'll just be reporting the value of the roll to the chat, this will work: !conjure [[1d10]] That's what gets sent. So we split on the space and assume everything after is our first argument, wherein we'd find our inline roll. let args = msg.content.split(/\s+/) The args array now has 2 elements... your handle and the roll. Now let's get the info from libInline... let parsed = libInline.getRollData(msg); And, finally, as we construct our outgoing message, we need to know *which* of the inline rolls we need to use. In other words, there might have been a simple roll like we used, or there could have been a more complex nested roll like [[[[1d20-[[{4,@{selected|ac}}kh1]]d6]]]]. Whatever was submitted in that position of the command line, what the Script Moderator sees is something like: !conjure $[[0]] ...where the index of the roll marker represents the final roll that your complex calculation resolved into. And that's what is in args[1] . So our next step is to extract that roll index so we can get the correct/matching index out of our parsed object: if (!/\$\[\[(\d+)]]/.test(args[1])) return; // you obviously might want to handle this situation differently let rollIndex =&nbsp; /\$\[\[(\d+)]]/.exec(args[1])[1]; Now rollIndex will have the index of the roll in your argument, so when you construct your outbound message, you can use this to get the matching roll out of the parsed object, and then drill down to the appropriate property you want: let m = `The roll was ${parsed[rollIndex].getRollTip()}.`; sendChat('Volcano Man', m); Give something like that a run and see if you have better luck.