If youre doing some kind of tabulated data in a script, you are generally better off building the table in a data variable in the script itself. RollableTables are terrible, and limited. If you avoid them, you will avoid the sendChat problem you are having. That said, the problem you are running into is due to the asynchronous nature of scripting in an internet environment. I dont do much async scripting, so cant help you much in getting it working, but knowing the nature of the issue might help you find answers yourself. I think you need to either get the rest of the script to wait for the results of that script, or do the rest of your script inside the callback function. As I said though, you can avoid this issue by building your table in a data object inside your script, and avoiding the async function altogether. You dont need to build the table from scratch - you can grab its contents from the tables object. To grab the table contents, first grab the table itself const table = findObjs ({
name: 'whatever the table is called',
_type: "rollabletable" ,
})[0]; //findObjs returns an array: [0] ensures you grab the first (and only) table in the array Using that, you can grab all the table items: const tableItems = findObjs ({
_rollabletableid: table.id,
_type: "tableitem" ,
}); You now have an array of the table item objects. Each object has a name property (the text in the table item), and a weight. If every item in your table is 1, you can convert this into a simple array like so: const tableRows = []; tableItems.forEach(item => { tableRows.push(item.get('name')); }); this is the same as the one-liner: const tableRows = tableItems.map(item => item.get('name')); You now have an array, tableRows, which is an array of the text values of the table items. You can then use randomInteger( tableRows.length() )-1 to get a result from the table. If the rows in the table have varying weights, there are a couple of ways to handle it, but the simplest is just to to create extra entries in the table for each weight. This should work: const tableRows = []; tableItems.forEach(item => {
const weight = +item.get('weight') || 1; // get weight as a number, with a default value of 1. for(let i = 0; i < weight; i++) { // add one row for each weight
tableRows.push(item.get('name'));
}
}); Then you can use the same randomInteger trick above to get a value off the table, like so: let tableResult = tableRows[randomInteger( tableRows.length() ) -1]; PS: noarchive just means the output isnt saved to the external chat archive. It doesnt affect the in-game chat. PPS: just realised I used const and let in place of var here, by habit. const is for variables that never change, and let is for everything else. You can use var in place of either of these if you are more comfortable with them. There are technical reasons for preferring them over var (they can help avoiding certain types of errors), but its not a big deal which you use. PPPS: just noticed my for loop had an error in it - it's been awhile since I used one of those, lol. Fixed it.