
I am just getting started in some personal scripting using the API, but I am wondering if I am doing something wrong here. I am trying to call a function to get the result of a die roll then store it to a variable for later use, but it seems to be delayed. Is there a better way to store die roll results for later use? Here is some simple code that can be used to show what I am seeing.
on("chat:message", function(msg) {
var rollvalue = "0";
if(msg.type == "api") {
if (msg.content == "!attack") {
var rollvalue = dieroll("d20");
log(rollvalue);
sendChat(msg.who, "roll result is " + rollvalue);
};
};
function dieroll (roll) {
sendChat(msg.who, "/roll 1" + roll, function(ops) {
var rollvalue = JSON.parse(ops[0].content).total;
log(rollvalue);
return rollvalue;
});
};
});