Nice idea. I havent looked closely at the script but I notice your respond function is a bit inefficient (unless there's some subtlety I'm missing - totally possible!). The issue is this bit: var characters = findObjs({_type: 'character'});
var speaking;
characters.forEach(function(chr) { if(chr.get('name') == msg.who) speaking = chr; }); You loop through all the characters, and get character name there, when you can do it in the findObjs function var character = findObjs({_type: 'character', name: msg.who})[0];
// this will be empty if no character of that name exists.
// if the character exists, use character id, otherwise player id
var speaking = character ? 'character|' + character.id: 'player|' + msg.playerid; This allows a simpler sendChat - no if statement: sendChat(speaking, out, null, {noarchive: true}); Both of these methods might not work properly if you have multiple characters with the same name, which is unfortunately possible. best avoid that! Also, I personally wouldnt pass the whole msg object to the function, I'd just pass the msg.playerid and msg.who parts, but that would require a bigger rewrite. One other point. You might have issues with this line if bar1_max is empty, or if the bars contain text: var bar1_percent = (tokens[0].get('bar1_value') / tokens[0].get('bar1_max')) * 5; I'd grab the value and max as variables and test them first, like var value = tokens[0].get('bar1_value');
var max = tokens[0].get('bar1_max');
// check bars aren't empty, and that they are numbers
if(value === '' || max === '' || isNaN(value) || isNaN(max) {
// an error message here
return;
}
// proceed with the calculation