That does help thanks. The reason I went down this road is because initially I was doing basically what you mentioned in the first scenario but it appeared I was unable to use the value assigned to rollvalue later. This could be because of what you mentioned before with the actual assigning happening later. In your first example, how can I use that rollvalue value later? Just using the code block you have it is still coming back as undefined, but I am looking to do something like this, the point being that a variety of things could happen or I could be making various rolls before I format them all into a pretty display. on("chat:message", function(msg) {
var rollvalue = "0";
if(msg.type == "api") {
if (msg.content == "!attack") {
sendChat(msg.who, "/roll 1+d20", function(ops) {
var rollvalue = ops[0].total;
});
sendChat(msg.who, "roll result is " + rollvalue);
};
};
});
Also, your second example is giving me the same results, undefined value. This is basically what prompted the question for me, because I agree it seems like these should work, but I am getting undefined back. on("chat:message", function(msg) {
if(msg.type == "api") {
if (msg.content == "!attack") {
sendChat(msg.who, "[[1+1d20]]", function(ops) {
var attackroll = ops[0].total;
sendChat(msg.who, "roll to hit: "+attackroll);
});
};
};
})
Now if I go with something like this it works fine, assuming I do something with the return right away, but I do not want to do that. on("chat:message", function(msg) { if(msg.type == "api") { if (msg.content == "!attack") { sendChat(msg.who, "/r 1d20", function(ops) { var attackroll = JSON.parse(ops[0].content).total;
sendChat(msg.who, "roll to hit: "+attackroll); }); }; }; }); I want to do something with the roll outside of the sendChat, so I can do things with it later. Just modifying the one that works right above this to move the sendchat outside of the other sendchat it does not store the value again. on("chat:message", function(msg) {
if(msg.type == "api") {
if (msg.content == "!attack") {
sendChat(msg.who, "/r 1d20", function(ops) {
var attackroll = JSON.parse(ops[0].content).total;
});
sendChat(msg.who, "roll to hit: "+attackroll);
};
};
});
Long story short, sounds like I should use the random integer, do you agree?