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
This post has been closed. You can still view previous posts, but you can't post any new replies.

[API] rollDice function...

The asynchronous nature of the sendChat command makes using it in an api script... daunting at best. I would like to have a rollDice() function that does basically the same thing as sendChat in regards to parsing dice, attributes, and such, but without the asynchronous nature that makes sendChat difficult to use.
As a Javascript noob who recently spent quite a few hours smashing my head against that particular wall, I second this idea. Unfortunately, I am out of votes.
1419972865
Lithl
Pro
Sheet Author
API Scripter
In the mean-time, you could implement an asynchronous semaphore. function Semaphore(callback, initial, context) { this.lock = initial || 0; this.callback = callback; this.context = context || callback; this.args = arguments.slice(3); } Semaphore.prototype = { v: function() { this.lock++; }, p: function() { var parameters; this.lock--; if (this.lock === 0 && this.callback) { // allow sem.p(arg1, arg2, ...) to override args passed to Semaphore constructor if (arguments.length > 0) { parameters = arguments; } else { parameters = this.args; } this.callback.apply(context, parameters); } } }; on('chat:message', function(msg) { // ... var sem = new Semaphore(function() { // does not need to be inline // ... }, 2); // supplying number of planned async operations means you don't need to call v() for each sendChat('', firstMessage, function(ops) { // ... sem.p(); }); sendChat('', secondMessage, function(ops) { // ... sem.p(); }); }); You don't have a guarantee what order the two sendChat calls execute, but you do have a guarantee that both have completed before the semaphore's callback fires. Of course, if you're only making one call to sendChat, you can simply call the function that would have been your callback directly (or put that code into the sendChat).
Have been banging my head against this particular wall for the past few hours. This has my vote.
Thanks for the suggestion! After 30 days, Suggestions and Ideas with fewer than 10 votes are closed and the votes are refunded to promote freshness. Your suggestion didn't build the right momentum this time, but feel free to submit it again! We find that the best suggestions describe the problem you are having, and the solution you want. You can learn more about the process of making suggestions on the Roll20 Wiki! More details can be found here .