
Back for some help from the api/js gurus. Not sure if the Topic makes any sense at all. Im trying to make a function that does the the same as this: sendChat('', "/roll [[1d6]]", function (ops) {
rollresult = JSON.parse(ops[0].content);
total = rollresult.total;
});
That I can call to do dynamic dice rolls in the API on the fly. OR a way to reference that 'total' outside of the send chat. As you can't read that var of total anywhere but inside that sendChat I tried var avc = DiceRoll("1d6");
function DiceRoll(dice) {
sendChat('', "/roll [[" + dice + "]]", function (ops) {
rollresult = JSON.parse(ops[0].content);
return rollresult.total;
});
}
log(avc);
But that doesn't seem to do what I expected it to..logging the variable after it is still undefined. Reason is I have a lot of places in scripts that uses entries on a players character sheet with values like 2D6 or 1D4*10..that gets exponentially complicated the more rolls I need to do inside one script as I have to nest sendChat inside sendChat inside sendChat..etc. to get all the totals as variables I can use. if I could find a way to convert such things as [[1d6]] [[4]] [[1d8+4]] into a result without having to nest tons of sendChats to get the result it would save me tons of headaches and many many lines of code. Let me see if I can clear it up some for an example. Say a api command is: "!cast --Test Spell --100 ft --2d6 --2d6 --50 --Casting Test Spell --1 ISP" I need to be able to turn 2d6, 3d6, and 50 into [[2d6]], [[3d6]] and [[50]]..which I can do just by wrapping the variable in [[ and ]] no problem. (the reason for doing the seemingly retarded thing of inline roll a 50..is that MAY be a 2d10 for someone else there..so I just inline all numbers..a [[50]] will return 50 anyway) Problem comes when I need to find the result of them..as you cant put [[something]] inside of a html div..it prints $[[1]] in chat like such Only way I can find is to keep nesting sendChats with function (ops) for each one so I can read the result, which gets messy in scripts i need to get 8-9 of them for. Also I cant really use 'msg.inlinerolls[0];' and such as that means it has to come into the chat as inline rolls..and making the players [[-]] all numbers on the character sheet is rather ugly and error prone. Anyone know a quick and easy way to change [[something]] into a number within a script without the need for the whole nested sendChats?