I have created a script to roll the indicated number of times on a table and save the results to a handout. The problem is, it comes up with the same result each time. The code is: /**
* Generates Hard Light Tombs for Stars Without Numbers Revised
*
* Syntax: !TG number of rooms
*
* option determines which set of rollable tables will be used for Background,
* equipment, and options such as Heritage or physical makeup
*/
var TG = TG || {
output: [],
listen: function () {
on('chat:message', function (msg) {
// Exit if not an api command
if (msg.type != "api") {
return;
}
if (msg.content.indexOf("!TG ") != -1) {
var input = msg.content.split(" ");
TombText = '';
switch (input[1]) {
case "help":
TG.showHelp;
default:
NumRooms = input[1];
for (let i = 0; i < NumRooms; i++) {
TG.genRoom(msg, TG.printRoom, TG.save);
sendChat('API', "/w gm <h6>Generating Tomb Location</h6>");
}
}
} else if (msg.content.indexOf("!TG") != -1) {
TG.showHelp();
}
});
},
showHelp: function () {
sendChat("API", "/direct <table style='background: #DCD9D5; border-radius: 20px; font-size: 10px;'>" +
"<thead><tr><th>Help</th></tr></thead>" +
"<tbody>" +
"<tr><td><strong>!TG [Number of Rooms]</strong><br>Generate the indicated number of tomb rooms.</td></tr>" +
"<tr><td><strong>!TG help</strong><br>Display this Help.</td></tr>" +
"<tr><td> </td></tr>" +
"</td></tr></tbody></table>");
},
genRoom: function (msg, outputCallback, saveCallback) {
TG.id = msg.playerid;
TG.name = "Room #"
TG.player = msg.who;
TG.rollRoom();
if (typeof outputCallback === "function") {
setTimeout(outputCallback, 2500, msg, saveCallback);
}
},
rollRoom: function () {
TG.TO = '';
sendChat("API", "/roll 1t[TombGen]", function (result) {
var content = JSON.parse(result[0].content);
TG.TO = content.rolls[0].results[0].tableItem.name;
});
},
printRoom: function (msg, saveCallback) {
var styleLabel = "style='font-weight: bold; padding: 5px;'";
var styleVal = "style='padding: 5px;'";
TombText = TombText + "<p><p>" + TG.TO;
// sendChat(msg.who, "/w gm " + TG.TO);
if (typeof saveCallback === "function") {
saveCallback();
}
},
save: function () {
var handout = createObj("handout", {
});
handoutId = handout.id;
handoutName = TG.name +' '+ handoutId.toString(16).toUpperCase();
handout.set('gmnotes', TombText);
handout.set('name', handoutName);
sendChat('API','/w gm <h6>Created '+ handoutName +'</h6>');
}
};
on("ready", function () {
TG.listen();
}); The other issue is that I want all the results in a single handout. What happens now is that a handout is saved after each iteration such that the first handout has the first result, the second has the first and second results, etc. How can I get a single handout with all the results? Suggestions?