First let me apologize for beating insanely on the rollserver trying to find this bug. My script is intermittently producing There was an error communicating with the QuantumRoll server.
I think it has to do with quick re-entry
to the rollserver in the same script; I found sendChat is non-blocking,
and it is possible to receive sendChats out of order, so they're
clearly not synchronous. Reproducing the error from my script is more
than tedious, so I pulled out one of the sendChats that was occasionally
failing, and hardcoded it into a tight loop as follows: var Testoonie = Testoonie || (function(){
var handleMsgInput = function(msg) {
if (msg.type !== "api" || msg.content.indexOf("!testoonie") === -1) return;
// fall through must be !testoonie - parse the opts
sendChat("Testoonie", "/roll 9d6");
var msgout = "&{template:5eDefault} {{action=1}} {{title=Ram}} {{subheader=Giant Elk}} {{subheaderright=Melee attack}} 0 {{action_show_attack=1}} {{action_attack=[[d20cs>20 + 6 + (0)]]}} {{action_show_attack_adv=1}} {{action_attack_adv=[[d20cs>20 + 6 + (0)]]}} {{action_can_crit=1}} {{action_crit_damage=[[2d6 + 0d0]]}} {{action_crit_damage_adv=[[2d6 + 0d0]]}} {{action_alt_crit_damage=[[0 + 0d0]]}} {{action_alt_crit_damage_adv=[[0 + 0d0]]}} {{action_second_crit_damage=[[0 + 0d0]]}} {{action_second_crit_damage_adv=[[0 + 0d0]]}} 0 {{action_show_damage=1}} {{action_damage=[[2d6 + 4 + (0) + 0d0]]}} {{action_damage_type=bludgeoning}} 0 0 0 0 0"
// var msgout = "/roll 10d10";
log(msgout);
for(var i=1; i<100;i++){
// sendChat(performerName, "" + i + "[[5d20]]" );
sendChat("Testoonie", msgout );
// sendChat(performerName, "" +i);
}
};
// END OF script input commands
var registerEventHandlers = function() {
on('chat:message', handleMsgInput);
};
return {
// CheckInstall: checkInstall,
RegisterEventHandlers: registerEventHandlers,
};
}());
on('ready',function() {
// 'use strict';
Testoonie.RegisterEventHandlers();
});
Interestingly, the message has to be complicated enough to produce the error. "/roll 10d20" for example wouldn't do it, regardless of how fast you pump it out. That's why the long attack-template roll message is in there. So it must have something to do with delaying the parsing of the message long enough to trigger a race condition (or something like that). At the current time, from my laptop, the above test script will consistently produce the "communicating" error, after about 40-60 chats are pumped. So if you pound on the rollserver hard enough, you'll get the error. I'm hoping the above is the same problem I'm having in my script. I guess I want to make sendChat block, or synchronize my script. But I'd rather not guess on what's going on here. Can you explain it? Will blocking on sendchat help, or will that just prevent every script from running? If I need to synchronize just ONE script and not all my running scripts, what strategy would you suggest? A script-specific semaphore? Is there an easy hook I can use or a pattern you'd suggest? I understand concurrency, but I am new to javascript, so I don't know much about JS's model of multiprocessing or multithreading. I doubt looking at my full script will help, but if you want: <a href="https://github.com/computed/rolledCode/tree/master" rel="nofollow">https://github.com/computed/rolledCode/tree/master</a>...