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

sendChat and /roll Issues

1594515642

Edited 1594517627
As part of my self-learning, I'm using this code in one of my scripts.&nbsp; It seems to work, but something weird has happened: //Rolling crossfire dice, 5 to hit or affect (in the case of anti-armour home brew rules) on("chat:message", function(msg) { //This allows players to enter !r5 &lt;number&gt; to roll a number of d6 dice with a target of 5 or 6. if(msg.type == "api" &amp;&amp; msg.content.indexOf("!r5 ") !== -1) { var numdice = msg.content.replace("!r5 ", ""); sendChat("Crossfire Roll: ", numdice + ' dice, 5 or 6 is a "hit"'); sendChat(msg.who, "/roll " + numdice + "d6&gt;5", null, {use3d: true}); } }); I adapted this from the Chat Event Example (Implementing Custom Roll Type) at: <a href="https://roll20.zendesk.com/hc/en-us/articles/360037256754#API:Chat-ChatEventExample(ImplementingCustomRollType)" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360037256754#API:Chat-ChatEventExample(ImplementingCustomRollType)</a> I need to alter the first sendChat to avoid a double colon, but that's peanuts to fix. Issue #1 - 3d Dice Display Different From Text Chat This screenshot shows the the results of entering !r5 4.&nbsp; The dice dice roll is 4, 1, 4, 5, with the 5 circled in red.&nbsp; But the text chat side window shows 4, 1, 4, 4 circled in red.&nbsp; It has worked very well up until the result below, and subsequent entry of !r5 4 and !r5 &lt;other numbers&gt; work as expected. I've repeated the !r5 4 entry a couple dozen times and can't reproduce a similar error as above.&nbsp; Can I write this off as a blip in the roll20 server, do you think?&nbsp; Or is there something off in my script, above? EDIT: Jeez, no, it just happened again. The documentation, quoted below, seems to suggest this is a new function for sendChat.&nbsp; There must be a bug of sorts, I think.&nbsp; Or would the bug be with the /Roll x d6&gt;5 statement, I wonder? Issue #2 - 3d Dice Colour You can see in the above screen shot that the dice are white.&nbsp; This is not a show stopper by any means, but it would be nice to have them roll in a player's assigned/chosen colour.&nbsp; According to the documentation following the above link, describing the use3d parameter for the options part of sendChat command: use3d &nbsp;-- You can now generate 3D Dice rolls using the sendChat() function. The syntax is simply:&nbsp; sendChat("Name", "Rolling [[3d6]]", null, {use3d: true}); &nbsp;If you pass a player ID to the name parameter, such as&nbsp; sendChat("player|-ABC123",...) &nbsp;the player's color will be used for the dice. Otherwise a default white color will be used. :) (Silly Americans, when will you learn to use U in your spelling!) :) It's a pity that the second sendChat name parameter, which is msg.who (see code above) is not sufficient.&nbsp; It would appear that I'd need to use a second variable, perhaps named strName, that is defined by a switch block that assigns the player operator in the above quote, with the default being msg.who.&nbsp; Would that work, do you think?&nbsp; It seems very cumbersome.
1594518651

Edited 1594518668
GiGs
Pro
Sheet Author
API Scripter
I cant comment on the 3d dice issues, since I dont use them, but this is how you pass a player's id to the output: sendChat('player|' + msg.playerid, "/roll " + numdice + "d6&gt;5", null, {use3d: true});
1594519245
The Aaron
Roll20 Production Team
API Scripter
If you look at my Tagmar script, it rolls 3D dice with player colors. (Colours, too!)
GiGs said: I cant comment on the 3d dice issues, since I dont use them, but this is how you pass a player's id to the output: sendChat('player|' + msg.playerid, "/roll " + numdice + "d6&gt;5", null, {use3d: true}); Perfect, that does fix the colour issue, thanks so much. :)&nbsp; Unfortunately, I think there's something truly ****ed with the sendChat method of rolling dice, LOL.&nbsp; Unless pasting !r5 4 time after time is what my issue is. I'll have a look at The Aaron's Tagmar script, I think.&nbsp; Take care. -- Tim
1594521886
GiGs
Pro
Sheet Author
API Scripter
Unless pasting !r5 4 time after time is what my issue is. I'm genuinely wondering if this is in fact the issue. sendChat is an asynchronus function, and with async functions, there's no guarantee they'll complete in the order you call them. It's possible you are seeing dice from different roll sequences. When you do a bunch of 3d dice rolls in quick sequence, it doesnt roll all of them.
The Aaron said: If you look at my Tagmar script, it rolls 3D dice with player colors. (Colours, too!) Thank you Aaron.&nbsp; I think I've overdone it today.&nbsp; I've looked at your script for tagmar on github and it's beyond my abilities at this time.&nbsp; I've installed Tagmar and am trying to use it, but having no success atm. The big take away for me is that sendChat is absolutely too unreliable to use for dice rolls.&nbsp; If it's that bad for dice rolls, I'm not sure I can trust it for anything else.&nbsp; Of course, I imagine sendChat must be used by character sheets to achieve rolls?&nbsp; Sorry, quite discouraged.&nbsp; I'll come back to in a day or two. Thanks so much for all your help in all my inquiries. -- Tim
1594523747
GiGs
Pro
Sheet Author
API Scripter
Tim M. said: The big take away for me is that sendChat is absolutely too unreliable to use for dice rolls.&nbsp; If it's that bad for dice rolls, I'm not sure I can trust it for anything else.&nbsp; Of course, I imagine sendChat must be used by character sheets to achieve rolls?&nbsp; Sorry, quite discouraged.&nbsp; I'll come back to in a day or two. It is reliable for dice rolls. You're the first person I've seen report the issue. One tip: if you are sending output from a script, you need to combine all the output that is meant to appear together into a single sendChat command. Try this and see if you can reproduce your issue: on("chat:message", function(msg) { //This allows players to enter !r5 &lt;number&gt; to roll a number of d6 dice with a target of 5 or 6. if(msg.type == "api" &amp;&amp; msg.content.indexOf("!r5 ") !== -1) { var numdice = msg.content.replace("!r5 ", ""); sendChat('player|' + msg.playerid, "**Crossfire Roll**\n/roll " + numdice + "d6&gt;5", null, {use3d: true}); } }); The \n inserts a linebreak so the two lines are combined into one sendChat command.
GiGs said: It is reliable for dice rolls. You're the first person I've seen report the issue. One tip: if you are sending output from a script, you need to combine all the output that is meant to appear together into a single sendChat command. Try this and see if you can reproduce your issue: on("chat:message", function(msg) { //This allows players to enter !r5 &lt;number&gt; to roll a number of d6 dice with a target of 5 or 6. if(msg.type == "api" &amp;&amp; msg.content.indexOf("!r5 ") !== -1) { var numdice = msg.content.replace("!r5 ", ""); sendChat('player|' + msg.playerid, "**Crossfire Roll**\n/roll " + numdice + "d6&gt;5", null, {use3d: true}); } }); The \n inserts a linebreak so the two lines are combined into one sendChat command. Thanks, Gigs.&nbsp; That works fine.&nbsp; I'm guessing my issue was a combination of having two sendChat commands and running the !r5 very quickly.