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

3D dice and the sendChat function

Hi folks, I'm hoping that someone may know the answer to this question. Based on the API documentation, the sendChat function allows for both a callback function as well as possible options. I was hoping that this would allow me to generate the 3D (some visual feedback for the players) dice roll and also do something with the result of the roll. I found that when I supplied a null for the callback and {use3d: true} option that I would get output to the chat and the 3D visual. However, when I supplied a callback and the {use3d: true} option that I would get no chat output and no 3D visual, but I can output results of the roll. Here is some example code to illustrate. This code is placed within the 'chat:message' event.  var cmd = msg.content.split(/\s+/); // this code sends the emote to the chat and rolls the dice sendChat('player|'+cmd[1], "/em Rolling the dice [[1d20+4]]", null, {use3d: true}); // this code doesn't send to the chat but it does output to the API output console. sendChat('player|'+cmd[1], "/em Rolling the dice [[1d20+4]]", function(ops){ for(var prop in ops) log('Name: ' + prop + '; Value: ' + ops[prop] + ';'); }, {use3d: true}); I would invoke the chat:message event by typing something like !test @{selected|character_id}. So my question would be, 1) Does supplying a callback eliminate output to chat? Is this a bug or by design? 2) Is there a way to create an API function that can capture the results of a roll and also provide the visual feedback to players. An example would be an attack function that you supply an inline roll. // !attack does something with the result of [[1d20]] and also rolls the 3D dice. !attack [[1d20]]
Yes, the callback eliminates the output to chat and prevents the use of 3D dice.
Thanks. Sky.
1493837953
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Scripts can respond to script generated chat messages, so you could have your script send the result to chat and then have a parser that would respond to that message.
1493838108
Jakob
Sheet Author
API Scripter
2) Is there a way to create an API function that can capture the results of a roll and also provide the visual feedback to players. An example would be an attack function that you supply an inline roll. You can get an on('chat:message') listener to parse the results of rolls in whatever format you like. Moreover, since sendChat commands (except for those supplied with a callback) trigger chat:message events, you can sends the rolls with a script to chat (using 3d dice, if you want to) and also have the API react to the content of the message.
Thanks Jakob. I found a number of posts that have given me some other ideas as well. Cheers.