Im working a script that does a few if logics to look at different tables. the issue Im running into is I cannot save what a rollable table returns to use later..which means I need to duplicate the entire 'what to do with it' into each table lookup and its messy. for example a snippet of what I'm doing: if (roll >= critRange) {
sendChat('', '/roll 1t[HitTable]', function (results) {
var text = JSON.parse(results[0].content).rolls[0].results[0].tableItem.name;
var output = "Lucky Shot: " + text;
});
//FAIL---------------------
} else if (roll <= failRange) {
sendChat('', '/roll 1t[Fumble]', function (results) {
text = JSON.parse(results[0].content).rolls[0].results[0].tableItem.name;
var output = "Fumble: " + text;
});
//normal roll---------------------
}
I have about 8 of these in the if/else if/else, but they are all along the same lines.. Returns the variable fine nside itself..but if I try to use 'output' anywhere outside that it returns undefined. The problem is I have quite a bit of other things it needs to do for it, send chat, format the text, etc.. It would be a lot easier to be able to just use 'output' of whichever was looked up in my if/else logic, in one final part at the bottom of my script to send to chat, then having to add ALL of the stuff to do inside each table lookup IF. Anyone got any tips? on how to look up in a rollable table and save the variable for outside the 'sendchat' that called it?