
So I'm trying to get a value back from this function:
function performRoll(msg, cmd) {
sendChat(msg.who, cmd, function(ops) {
var resultTotal = 0;
if (ops[0].type == 'rollresult') {
var result = JSON.parse(ops[0].content);
var addSucc = 0;
var strSplit = ops[0].origRoll.split('-');
var cmds = [];
_.each(strSplit, parseCmds, cmds);
if (!_.isEmpty(cmds)) {
resultTotal=processCmds(cmds, result);
} else {
// If there are no commands passed, the script defaults to doubling 10s, which is what this call represents.
resultTotal=doDoubles(result, true, 0);
} // if
// This gets the player's color, for styling the roll result HTML output in buildHTML().
var player = getObj("player", msg.playerid);
var outHTML = buildHTML(result, msg.content, ops[0].origRoll, player.get('color'));
// Passes the final, formatted HTML as a direct message to the chat window.
sendChat(msg.who, '/direct ' + outHTML);
return resultTotal;
} else {
// Error handling.
printError(ops[0], msg.who);
} // if
});
} // performRoll
I'm trying to get the resultTotal variable out of the function, but it's some sort of javascript lambda function.
How can I restructure this so that I can return resultTotal back to the caller of performRoll?